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

Default Values in Multiple Inheritance

In single inheritance, a class has the same default values that its parent class has, except where the class overrides those values with values of its own. This property results from the fact that the class has only one parent, and therefore only one source from which it can inherit default value definitions.

In multiple inheritance, specifying a class as the primary direct superior does not guarantee that the subclass inherits all default values from that class. A subclass inherits the default value of an attribute from the first class in the class inheritance path that explicitly defines one, not from the first class that has one by inheritance.

The examples in this section show how G2 uses the class inheritance path to determine which default values a multiple inheritance class inherits. The examples focus on the system-defined attribute Icon-description, which defines the icon displayed by an instance. The examples use the PC-NET multiple inheritance structure:


PC-NET's direct superiors are PC and NETWORK, in that order; PC's class inheritance path is therefore:

Inheriting a Default Value from a Direct Superior

In the next figure, both the PC and NETWORK classes have their own icon definitions. As in the previous example, the icon by PC is called the workstation icon, and the icon by NETWORK is called the node icon.


Since PC appears before NETWORK on PC-NET's class inheritance path, PC-NET inherits the workstation icon.

NETWORK's icon definition has no effect on PC-NET: from PC-NET's perspective, NETWORK's icon definition does not exist: PC's definition has overridden NETWORK's definition.

If you deleted PC's icon definition, and did not define any other icon on the path between PC-NET and NETWORK, NETWORK's icon definition would cease to be overridden, and would be PC-NET's icon definition also. A PC-NET instance would then have a node icon.

Overriding the Default Value of a Direct Superior

In the next figure, PC does not define an icon, but COMPUTER and NETWORK do:


Since COMPUTER appears before NETWORK on PC-NET's class inheritance path, PC-NET inherits the workstation icon: the default value given by NETWORK, a direct superior is overridden. The class inheritance path, not the list of direct superiors, determines default value inheritance.

Overriding an Inherited Value with an Explicit Value

In the next figure, NETWORK and EQUIPMENT both define icons:


Since NETWORK appears before EQUIPMENT on PC-NET's class inheritance path, PC-NET inherits the node icon: the default value that PC inherits from EQUIPMENT via COMPUTER is overridden. Only explicit specifications, not inherited specifications, can provide default values.

Inheriting Default Values for Stubs

Icons and stubs are closely related, but they are specified by two different attributes of a definition. Where multiple inheritance exists, this independence could result in mismatched icons and stubs, so the G2 class inheritance rules contain a special provision that prevents it.

To prevent such a mismatch, a class can inherit a stubs definition only from the class from which it inherits its icon definition, or from a descendent of that class. If none of these provides a stubs definition, either inherited or locally defined, the class's stubs default value is none.

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

Copyright © 1997 Gensym Corporation, Inc.