next up previous

9.3.1.1 Multiple Inheritance Rules

COOL uses the inheritance hierarchy of the direct superclasses to determine the class precedence list for a new class. COOL recursively applies the following two rules to the direct superclasses:

1) A class has higher precedence than any of its superclasses.

2) A class specifies the precedence between its direct superclasses.

If more than one class precedence list would satisfy these rules, COOL chooses the one most similar to a strict preorder depthfirst traversal. This heuristic attempts to preserve "family trees" to the greatest extent possible. For example, if a child inherited genetic traits from a mother and father, and the mother and father each inherited traits from their parents, the child's class precedence list would be: child mother maternal-grandmother maternal-grandfather father paternal-grandmother paternal-grandfather. There are other orderings which would satisfy the rules (such as child mother father paternal-grandfather maternal-grandmother paternal-grandmother maternal-grandfather), but COOL chooses the one which keeps the family trees together as much as possible.

Example 1

(defclass A (is-a USER))

Class A directly inherits information from the class USER. The class precedence list for A is: A USER OBJECT.

Example 2

(defclass B (is-a USER))

Class B directly inherits information from the class USER. The class precedence list for B is: B USER OBJECT.

Example 3

(defclass C (is-a A B))

Class C directly inherits information from the classes A and B. The class precedence list for C is: C A B USER OBJECT.

Example 4

(defclass D (is-a B A))

Class D directly inherits information from the classes B and A. The class precedence list for D is: D B A USER OBJECT.

Example 5

(defclass E (is-a A C))

By rule #2, A must precede C. However, C is a subclass of A and cannot succeed A in a precedence list without violating rule #1. Thus, this is an error.

Example 6

(defclass E (is-a C A))

Specifying that E inherits from A is extraneous, since C inherits from A. However, this definition does not violate any rules and is acceptable. The class precedence list for E is: E C A B USER OBJECT.

Example 7

(defclass F (is-a C B))

Specifying that F inherits from B is extraneous, since C inherits from B. The class precedence list for F is: F C A B USER OBJECT. The superclass list says B must follow C in F's class precedence list but not that B must immediately follow C.

Example 8

(defclass G (is-a C D))

This is an error, for it violates rule #2. The class precedence of C says that A should precede B, but the class precedence list of D says the opposite.

Example 9

(defclass H (is-a A))
(defclass I (is-a B))
(defclass J (is-a H I A B))

The respective class precedence lists of H and I are: H A USER OBJECT and I B USER OBJECT. If J did not have A and B as direct superclasses, J could have one of three possible class precedence lists: J H A I B USER OBJECT, J H I A B USER OBJECT or J H I B A USER OBJECT. COOL would normally pick the first list since it preserves the family trees (H A and I B) to the greatest extent possible. However, since J inherits directly from A and B, rule #2 dictates that the class precedence list must be J H I A B USER OBJECT.


next up previous