Single inheritance is very straightforward: a subclass inherits everything characteristic of its direct superior class (parent). If you do not redefine any system-defined attributes in the subclass definition, or add any class-specific attributes to the definition, an instance of the subclass differs only in name from an instance of its parent class.
Single inheritance is convenient where information is tree-structured, or sufficiently close to it that an acceptable amount of duplication in class definitions can make up the difference. Single inheritance can usually provide everything that a user-defined class hierarchy needs.
Where information is not tree-structured, you can use multiple inheritance to represent the information efficiently. Multiple inheritance differs from single inheritance in that it allows a subclass to have more than one direct superior class.
Various complexities can arise in multiple inheritance, because the parent classes can include duplicate and conflicting attributes. If you understand how G2 copes with these, as described later in this chapter, you should have no difficulty using multiple inheritance.
Every definition has two attributes for controlling and displaying inheritance:
Direct-superior-classes and Class-inheritance-path. You must understand these attributes in order to understand G2 inheritance.
When more than one direct superior class exists, the order in which they appear in the
Direct-superior-classes attribute, in conjunction with the structure of the existing class hierarchy, determines the class inheritance path, which controls what happens in case of duplicate or conflicting inheritance.
ITEM. The contents of the list between the immediate class and the root class vary with the details of the immediate class's inheritance. G2 automatically derives a class's inheritance path based on its direct superior class(es) and the existing class hierarchy, and updates the path as needed when you modify the hierarchy.
G2 uses a class's inheritance path to resolve duplicate and conflicting attributes among the superior classes that the class inherits. Such resolution is exactly the same in single and multiple inheritance: G2 scans the class inheritance path and gives precedence to the first relevant attribute definition that it encounters.
Since the immediate class is always the first class on its own inheritance path, this technique allows a class to override, or shadow, any inherited attribute definition with a definition of its own.