Direct-superior-classes attribute.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 PERIPHERAL and 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:
Primary (PERIPHERAL)
|
Secondary (NETWORK)
| |
|---|---|---|
EQUIPMENT
|
|
EQUIPMENT
|
PERIPHERAL
|
PERIPHERAL
| |
|
NETWORK
|
The problem is that the resulting class inheritance path,
PC-NET, NETWORK, PERIPHERAL, 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.PERIPHERAL > NETWORK in PC-NET's direct superior list, yet PERIPHERAL < NETWORK in 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 PERIPHERAL and 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 G2-WINDOW and CONNECTION. The resulting class would be nonsensical.
INTEGER-ARRAY is a subclass of OBJECT, which is a subclass of ITEM, and NETWORK-WIRE is a subclass of CONNECTION which is a subclass of ITEM.
![]() |
A user-defined class could inherit from a combination of
ITEM, OBJECT, and INTEGER-ARRAY, because all three are in the same line of inheritance. Similarly, a user-defined class could inherit from any combination of ITEM, CONNECTION, and NETWORK-WIRE. However, a class that tried to inherit OBJECT and NETWORK-WIRE, or any other combination of foundation classes in different lines of inheritance, would be illegal.