[Interest] How to do it better?
Till Oliver Knoll
till.oliver.knoll at gmail.com
Tue Dec 30 00:04:50 CET 2014
> Am 29.12.2014 um 22:15 schrieb Igor Mironchik <igor.mironchik at gmail.com>:
> 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).
More information about the Interest