Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #68311
| Newsgroups | comp.lang.c++ |
|---|---|
| From | JiiPee <no@notvalid.com> |
| Subject | Action/logic inside or outside the Windows class? |
| Message-ID | <Jb4eF.975226$dw4.193344@fx12.am4> (permalink) |
| Organization | virginmedia.com |
| Date | 2019-09-11 11:41 +0100 |
I know this is not Windows programming forum, but because I think this
is more like a C++ expertise question (and not Windows) I ask here.
So lets say I have a window where I show text after some mouse click. A
naive program, but just to keep it simple.
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?
Should all message handler functions forward the call to the program
logic class? So all message handler functions in Window class
should contain normally only 1 line (see example below)?
So which one is better 1) or 2) (ignoring the effiency/style issues...)?
I try to make an example illustrating the two approaches
(GetDocument() returns a document object which contains the text
variable drawMessage_):
1) Mouse logic left in MyWindow class:
class MyWindow
{
public:
void Draw() {
// draws GetDocument()->drawMessage_ text on to the window
}
void MouseClick(Point mousePosition);
};
void MyWindow::MouseClick(Point mousePosition)
{
if(mousePosition.x > 150)
{
GetDocument()->drawMessage_ = "Mouse crossed the border";
Draw();
}
}
========================================================================
2) Mouse logic done in MyWindowLogic class:
class MyWindowLogic
{
public:
void Draw() {
// draws GetDocument()->drawMessage_ text on to the window
}
void HandleMouseClick(Point mousePosition);
};
void MyWindowLogic::HandleMouseClick(Point mousePosition)
{
if(mousePosition.x > 150)
{
drawMessage_ = "Mouse crossed the border";
Draw();
}
}
///////////////////////////
class MyWindow
{
public:
void Draw() {
logic.Draw(); // forward all action to the logic class
}
void MouseClick(Point mousePosition);
private:
MyWindowLogic logic;
};
void MyWindow::MouseClick(Point mousePosition)
{
logic.HandleMouseClick(mousePosition); // do all action in logic class
}
###########
If it an overkill to create a new class for this rather than place all
code in the MyWindow class?
Should we keep things "simple" here and place all such code in the
MyWindow class?
Or this kind of separation of logic/windows code is good?
Back to comp.lang.c++ | Previous | Next — Next in thread | Find similar | Unroll thread
Action/logic inside or outside the Windows class? JiiPee <no@notvalid.com> - 2019-09-11 11:41 +0100
Re: Action/logic inside or outside the Windows class? Öö Tiib <ootiib@hot.ee> - 2019-09-11 06:45 -0700
Re: Action/logic inside or outside the Windows class? JiiPee <no@notvalid.com> - 2019-09-11 15:28 +0100
Re: Action/logic inside or outside the Windows class? Öö Tiib <ootiib@hot.ee> - 2019-09-12 01:05 -0700
Re: Action/logic inside or outside the Windows class? JiiPee <no@notvalid.com> - 2019-09-11 15:45 +0100
Re: Action/logic inside or outside the Windows class? JiiPee <no@notvalid.com> - 2019-09-11 15:53 +0100
Re: Action/logic inside or outside the Windows class? JiiPee <no@notvalid.com> - 2019-09-11 15:58 +0100
Re: Action/logic inside or outside the Windows class? Paavo Helde <myfirstname@osa.pri.ee> - 2019-09-11 18:22 +0300
Re: Action/logic inside or outside the Windows class? JiiPee <no@notvalid.com> - 2019-09-11 16:45 +0100
Re: Action/logic inside or outside the Windows class? Paavo Helde <myfirstname@osa.pri.ee> - 2019-09-11 19:12 +0300
Re: Action/logic inside or outside the Windows class? JiiPee <no@notvalid.com> - 2019-09-11 17:51 +0100
Re: Action/logic inside or outside the Windows class? red floyd <dont.bother@its.invalid> - 2019-09-11 09:56 -0700
Re: Action/logic inside or outside the Windows class? JiiPee <no@notvalid.com> - 2019-09-11 19:42 +0100
Re: Action/logic inside or outside the Windows class? Paavo Helde <myfirstname@osa.pri.ee> - 2019-09-11 20:24 +0300
Re: Action/logic inside or outside the Windows class? JiiPee <no@notvalid.com> - 2019-09-11 19:42 +0100
csiph-web