18.3 The class precedence list

When each class has only one direct superclass, the relations among superclasses and subclasses form a tree. For every subclass in the tree, there is a well-defined ordering in terms of specificity for that class and all its superclasses. A subclass is always more specific than are any of its superclasses. When each class has only one superclass, we can order unambiguously any given class and all its superclasses, from most specific to least specific. Figure 18.1 illustrates part of such an ordering for our original, single-inheritance definitions of <vehicle> and <vehicle>'s subclasses.

With multiple inheritance, the relations among superclasses and subclasses can form a graph, which may not be a tree. We cannot always order a class and all its superclasses in terms of specificity. It is still true that a subclass is more specific than are any of its superclasses. But we cannot always order its superclasses in terms of specificity.

Figure 18.2 illustrates our current definitions of <vehicle> and of <vehicle>'s subclasses.

Figure 18.2 Graph of vehicle classes that use multiple inheritance.
Figure 18.2

Consider <B707> and its superclasses. We can order <B707>, <commercial-aircraft>, and <aircraft> from more specific to less specific. But we cannot say that either <ground-vehicle> or <flying-vehicle> is more specific than the other, because neither class is a subclass of the other. We could order <B707> and its superclasses in two ways, from more specific to less specific:

<B707>, <commercial-aircraft>, <aircraft>,
  <flying-vehicle>, <ground-vehicle>, <vehicle>, <physical-object>, <object>
<B707>, <commercial-aircraft>, <aircraft>,
  <ground-vehicle>, <flying-vehicle>, <vehicle>, <physical-object>, <object>

Dylan needs a way to determine which of these orderings to use. It solves the problem by constructing a class precedence list for <B707> and its superclasses.