[Interest] How to do it better?

Igor Mironchik igor.mironchik at gmail.com
Tue Dec 30 05:24:46 CET 2014


Hi,

cool, after a whole day of work my brain is clouded.

Great thanks.

On Tue, 30 Dec 2014 02:04:50 +0300, Till Oliver Knoll  
<till.oliver.knoll at gmail.com> wrote:

>
>
>> Am 29.12.2014 um 22:15 schrieb Igor Mironchik  
>> <igor.mironchik at gmail.com>:
>>
>> Hi,
>>
>> I have a base class and derived from it one. I want that in derived  
>> class
>> occurs some event (for example QResizeEvent) when I change one property  
>> in
>> base class. I need to recalculate size when this property changes.
>
> This is a design pattern related question, and as such not directly  
> related to Qt (nor C++, for that matter). Unless you would be asking  
> "How to implement design pattern Foo best with Qt".
>
> A 5 seconds brainstorming (after some excellent whiskeys at a friend's  
> place) came up with the conclusion (one of a gadzillion others) that you  
> should be following the Template pattern: provide a setter/getter pair  
> to that (private) property in your base class, where the setter calls a  
> (virtual) "template" method (leave it pure virtual in the base class, or  
> provide some meaningful default implementation, which can also be "doing  
> nothing at all".
>
> Then in your derived class overwrite that "template" method and provide  
> any meaningful implementation there (in the context of that derived  
> class).
>
> Cheers,
>   Oliver
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest


-- 
Best Regards,
Igor Mironchik.



More information about the Interest mailing list