| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (12 out of 18)

Illegal Patterns of Multiple Inheritance

G2 prohibits you from specifying some patterns of multiple inheritance because they would cause disordered or meaningless results. If you specify an illegal pattern of multiple inheritance, G2 displays a descriptive error message when you try to close the edit of the 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.

Disordered Multiple Inheritance

Some patterns of multiple inheritance are illegal because the resulting inheritance could not have a logically ordered linearization. To get a general idea of this type of illegal inheritance, consider the following figure:


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.

This specification is illegal because 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.

To prevent this kind of problem, G2 requires that any class specified in a list of direct superiors must precede any superior class that also appears. That is, a more general class cannot take precedence over a more refined subclass in a list of direct superiors.

This restriction is an example of the general principle that multiple inheritance must not compromise strict hierarchy. The contradiction between 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.

In the current example, you could solve the problem by reversing the order of inheritance, so that 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.

This illustrates a general principle of multiple inheritance: where illegal multiple inheritance occurs, something is probably wrong with the plan that led to it.

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.

G2 defines any system-defined concrete or abstract class as a foundation class. To prevent meaningless multiple inheritance, G2 enforces the following rule:

For example, 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.

As pointed out in the previous subsection, inheriting both a class and a direct superior of that class serves no purpose, because the class already has everything that the superior has. However, G2 applications sometimes define subclasses of different foundation classes, then combine those subclasses using multiple inheritance. Such a subclass can exist only when all foundation classes in its ancestry are in the same line of inheritance.

| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (12 out of 18)

Copyright © 1997 Gensym Corporation, Inc.