[Interest] Qt 5.5.x

Till Oliver Knoll till.oliver.knoll at gmail.com
Fri Sep 11 19:41:01 CEST 2015

> Am 11.09.2015 um 18:48 schrieb "md at rpzdesign.com" <md at rpzdesign.com>:
> Mr Weeks -> You were correct.
> A dependency was touched. And that had a domino effect on untouched code.

You can further reduce the "dependency tree" of your sources by making use of the private "d-pointer" pattern (there is a name for it which currently escapes me - Qt itself makes heavy use). That is, you move the declaration of all your (private/protected) members into a "private class", implemented in the corresponding *.cpp. It gets a bit tricky for protected members, if you need to access them "directly" (without setter/getter) from subclasses. But there's a solution for that, too, with the "d-pointer pattern" - see Qt sources ;)

By moving all member declaration and instantiation away from the class *.h header into the *.cpp file you potentially avoid indirect dependencies. Even more, now you can add/change/remove class members without changing the class header! No invalidation of sources which use your class (read: no recompile).

Another "trick": pass along arguments as references/pointers and use "forward declarations in your headers (#include the other headers only in your implementation *.cpp files).

In general: only #include what's really necessary, where it is necessary.

Oh, and don't use libraries which make heavy use of templates such as boost ;) (the last point not to be taken too seriously. But template expansion might generate quite a lot of code, might generate additional dependencies and in general creates additional work for the parser, prolonging compile time in general).


More information about the Interest mailing list