As long as you use multiple inheritance in straightforward ways, you will rarely if ever specify an illegal pattern of multiple inheritance. Thus you do not need to study the subject in detail so as to avoid trouble later on. This section describes the general nature of the two types of illegal inheritance.
The figure indicates that the
PC-NET subclass specifies its direct superior classes as
NETWORK, in that order
. NETWORK specifies
PERIPHERAL as its sole superior class.
NETWORK would be unable to precede
PERIPHERAL in the class inheritance path as it should. Note that the problem is not that G2 cannot linearize PC-NET's class inheritance path:
The problem is that the resulting class inheritance path,
EQUIPMENT, gives the secondary direct superior,
NETWORK, precedence over the primary direct superior,
PERIPHERAL. This is not a case of compromising the order of classes inherited through different direct superiors: the direct superiors themselves are out of order.
PC-NET's direct superior list, yet
PC-NET's class inheritance path, is an example of the kind of disorder that would result if strict hierarchy were compromised.
PC-NET specifies its direct superior classes as
NETWORK, in that order. However, such a specification, though not illegal, is pointless:
PC-NET already inherits from
NETWORK anything it would inherit from
PERIPHERAL. Thus there is no need for multiple inheritance in this case.
Meaningless Multiple Inheritance
Some patterns of multiple inheritance are illegal because the resulting class could not serve a reasonable purpose. For example, consider a class that inherits
CONNECTION. The resulting class would be nonsensical.
INTEGER-ARRAYis a subclass of
OBJECT, which is a subclass of
NETWORK-WIREis a subclass of
CONNECTIONwhich is a subclass of
A user-defined class could inherit from a combination of
INTEGER-ARRAY, because all three are in the same line of inheritance. Similarly, a user-defined class could inherit from any combination of
NETWORK-WIRE. However, a class that tried to inherit
NETWORK-WIRE, or any other combination of foundation classes in different lines of inheritance, would be illegal.