Thinking in C++ Vol 2 - Practical Programming |
Prev |
Home |
Next |
One reason MI exists in C++ is that it is a hybrid language
and couldn t enforce a single monolithic class hierarchy the way Smalltalk and
Java do. Instead, C++ allows many inheritance trees to be formed, so sometimes
you may need to combine the interfaces from two or more trees into a new class.
If no diamonds appear in your class hierarchy, MI is
fairly simple (although identical function signatures in base classes must
still be resolved). If a diamond appears, you may want to eliminate duplicate
subobjects by introducing virtual base classes. This not only adds confusion,
but the underlying representation becomes more complex and less efficient.
Multiple inheritance has been called the goto of the 90s. This seems
appropriate because, like a goto, MI is best avoided in normal programming, but
can occasionally be very useful. It s a minor but more advanced feature of
C++, designed to solve problems that arise in special situations. If you find
yourself using it often, you might want to take a look at your reasoning. Ask
yourself, Must I upcast to all the base classes? If not, your life will be
easier if you embed instances of all the classes you don t need to
upcast to.
Thinking in C++ Vol 2 - Practical Programming |
Prev |
Home |
Next |