Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #68330

Re: Action/logic inside or outside the Windows class?

From Paavo Helde <myfirstname@osa.pri.ee>
Newsgroups comp.lang.c++
Subject Re: Action/logic inside or outside the Windows class?
Date 2019-09-11 19:12 +0300
Organization A noiseless patient Spider
Message-ID <qlb6d3$1rk$1@dont-email.me> (permalink)
References <Jb4eF.975226$dw4.193344@fx12.am4> <qlb3ff$e8j$1@dont-email.me> <5E8eF.1039614$c8w1.775269@fx08.am4>

Show all headers | View raw


On 11.09.2019 18:45, JiiPee wrote:
> On 11/09/2019 16:22, Paavo Helde wrote:
>> On 11.09.2019 13:41, JiiPee wrote:
>>> 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?
>>
>> In general, yes, in the Window class you should have only
>> windows-related logic.
>>
>> Another way to think about that is that you want to put all your
>> program logic under unit tests control anyway. Simulating mouse clicks
>> for unit testing might not be so simple and would mix up testing the
>> GUI and the program logic, so most of the program should be testable
>> without GUI.
>>
>> So ideally you should first write your program logic classes together
>> with unit tests. Once the functionality is working and the tests are
>> passing, only then start adding windows related classes to expose this
>> functionality in GUI. Refactor, rinse and repeat as needed, unit tests
>> are now there and holding the functionality intact.
>>
>
> Did I understand correctly that you prefer something like 2)? that the
> mouse action code is not in the Windows class at all?

No, in your example you just forwarded some GUI related logic to another 
class, for no obvious reason. GUI logic should remain in the GUI 
classes. In general, the program logic classes should not contain word 
"mouse" or "click".

If you click a mouse "out of the border", this might affect the program 
logic or not. Maybe you want to call PauseCalculation() on your app, for 
example. If there really is no other effect than changing a message 
string, then the mouse click function should call 
logic.SetStatusMessage("...") or something like that.

Of course, borders are fuzzy here. YMMV.


Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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