On Wednesday, 11 September 2019 17:28:31 UTC+3, JiiPee wrote:
> On 11/09/2019 14:45, Öö Tiib wrote:
> > On Wednesday, 11 September 2019 13:41:55 UTC+3, JiiPee wrote:
> > The question is that should I have only windows-related code in the
> >> Window class and create another class dealing
> >> with the logic of the program?
> > GUI code is often made to deal with human operator's input and output
> > and only with it. Then they do not put into GUI classes any code that
> > a) inputs from any other sources
> > b) processes the data that was acquired from any sources
> > c) or outputs its results to any other targets
>
>
> Thanks
>
>
> Can you give 1-2 examples pls?
It is tricky to give examples of all those architectural
patterns how to separate "presentation layer" of software from other
layers (like "service layer", "business logic layer", "persistence layer").
There are tons of materials to read about various takes on it like
"model-view-adapter", "presentation-action-control" or
"model-view-viewmodel".
> Does for example b) mean that processing
> for example database issues:
>
> void MyWindow::MouseClick(Point mousePosition)
> {
> if(mousePosition.x > 150)
> {
> // -open database
>
> // -add line into database
>
> Draw();
> }
> }
>
>
> should not be done like that in MyWindow class? because database is an
> outside source?
Yes.
> > and basically ... that is it.
> > Since your example task lacked responsibilities to do anything
> > of those a), b) or c) it is bad example how to split responsibilities
> > that way.
>
>
> but it answer the question that mouse related code can be done in
> MyWindow, I understand. This is a real world example, because
>
> I process mouse input in my message handlers.
For rest of application there should be no such thing as
"mouse", "window" or "keyboard". Application should have
purpose.
> > Note that those a), b) and c) are usually called "program
> > logic" by such split.
> >
>
>
> ok, so in my example program you would prefer:
>
> void MyWindow::MouseClick(Point mousePosition)
> {
> if(mousePosition.x > 150)
> {
> GetDocument()->drawMessage_ = "Mouse crossed the border";
> Draw();
> }
> }
>
>
> so checking/processing the mouse values in MyWindow class function.
It is hard to explain since that MyWindow should have meaning,
the line where x is 150 should have meaning and clicking should
be meaningful gesture. Your examples lack any meaning whatsoever
so those can't be used for discussing what you want to discuss.
Better take something that has meaning, even if the meaning is
absurdly simple, for example how to separate tic-tac-toe game
and GUI for it.