Fully Qualified
When I’m coerced into inheriting from one or more base classes to reuse pre-existing functionality, I prefer to fully qualify my calls to base class member functions like this:
Coding this way helps me to keep a conceptual separation between classes and eases downstream maintenance – I know where to look for the function definitions. Since I’m a “has a” instead of an “is a” programmer, I prefer black box composition over white box inheritance; unless it’s necessary or authoritative coercion is involved. How about you? What’s your preference?
Categories: C++
c++, linkedin, postaday2011, programming, software design
Under the Windows environment, I use the keyword __super. In Linux environment, I just typedef __super with the parent class.
It’s subjective, but I feel that it is cleaner because it distinguishes super class method calls and static member function calls from some helper class.
When it comes to multiple inheritance (fairly rare), I usually follow your example and use the fully qualified name.
… Alan
Thanks for weighing in Alan. I didn’t know about the Win compiler __super keyword. I think any “idiom” that allows a maintainer to easily distinguish between calls to the base class(es) is great.
Because of the potential to introduce nasty, hard to find bugs & deadly diamonds, I think MI should be used rarely too. Alas, I’ve had to work in several code bases where there’s lots of MI mixins – with some classes inheriting multiply from up to 3 classes. D’Oh!