Multiple Inheritance
Line 24: | Line 24: | ||
==See Also== | ==See Also== | ||
+ | * [[Arthur Riel 1996]] | ||
* [[Avoid multiple inheritance]] | * [[Avoid multiple inheritance]] |
Revision as of 01:59, 23 July 2009
Multiple Inheritance (MI) occurs when a subclass has two or more super classes.
It is an available construct in C++, Eiffel and Perl. However, it is not available in Java or C#.
Multiple Inheritance is often considered a desirable feature of OO languages However, Riel claims, with relation to the introduction of MI to C++, that "...only 2 percent [of developers] understood why they wanted multiple inheritance and were not misusing it."
Contents |
Acceptable Usage
Riel believes it is acceptable to use MI when the two classes that are being subclasses provide two real concepts that both provide a necessary, objective, component of the created subclass. UML coming
Unacceptable Usage
Riel believes that it is not acceptable to use MI when:
- it is for the purpose of composition, e.g. an Aircraft should not inherit from Wings or a Cockpit.
- the inheritance hierarchy is poorly defined, e.g an Orange should not inherit from Citrus and Food. It should inherit from Citrus, which should, in turn, inherit from Food.
'Mixins' and DAGs
Coming soon!
Non-MI Languages
In languages that do not support MI, several techniques can be used to provide equivalent functionality.
- The essential superclass has to be defined.
- Subclasses can aggregate instances of classes designed to provide the functionality of the other superclasses.
- Interfaces can be used to make sure classes support specific methods and have a specific form (most OO languages can implement multiple interfaces).