Increasing Reusability - Multiple inheritance Print E-mail
Wednesday, 31 January 2001 09:24
Article Index
Increasing Reusability
Classification and inheritance
Shape class hierarchy
Multiple inheritance
All Pages

Multiple Inheritance

In the Shape class hierarchy, we’ve seen single inheritance, where each class (except the root) has one and only one superclass, though a class can have multiple subclasses. Consider this alternative hierarchy:

A Rectangle is defined as a Quadrilateral with four right (90°) angles, while a Rhombus is a Quadrilateral with four equal sides. A Square has four right angles and four equal sides, so it inherits the properties of both a Rectangle and a Rhombus. This is an example of multiple inheritance. C++ permits multiple inheritance in addition to single inheritance, and it gives a lot of flexibility in coding, as it more accurately models many real-world situations.

Multiple inheritance has one major drawback: when a class inherits members with the same name from two different classes, how do you figure out which one to use? Resolving this apparently simple problem can actually be such a nightmare that many OOPLs, like Smalltalk and Java, decide that it’s simply not worth the hassle (Gallagher 1990; Sutherland 1995; Wyant 1995).



Last Updated on Tuesday, 28 October 2008 14:51