next up previous
Next: Object Identity Up: The Object-Oriented Data Model Previous: Inheritance

Multiple Inheritance

  1. In most cases, tree-structured organization of classes is adequate to describe applications. In such cases, all superclasses of a class are ancestors of descendants of another in the hierarchy. However, there are situations that cannot be represented well in a tree-structured class hierarchy.
  2. Example. We could create subclasses: part-time-teller, full-time-teller, etc., as shown in Fig. 8.4. But problems: (1) redundancy leads to potential inconsistency on updates; and (2) the hierarchy cannot represent full/part- time employees who are neither secretaries nor tellers.

      figure184
    Figure 8.4:  Class hierarchy for full- and part-time employees.

  3. Multiple inheritance: the ability of class to inherit variables and methods from multiple superclasses.
  4. The class/subclass relationship is represented by a rooted directed acyclic graph (DAG) in which a class may have more than one superclass.

      figure190
    Figure 8.5:  Class DAG for the banking example.

  5. Handling name conflicts: When multiple inheritance is used, there is potential ambiguity if the same variable or method can be inherited from more than one superclass.
  6. Example. In our banking example, we may define a variable pay for each full-time, part-time, teller and secretary as follows:

  7. For part-time-secretary, it could inherit the definition of pay from either part-time or secretary. We have the following options: No single solution has been accepted as best, and different systems make different choices.
  8. Not all cases of multiple inheritance lead to ambiguity. If, instead of defining pay, we retain the definition of variable salary in class employee, and define it nowhere else, then all the subclasses inherit salary from employee (no ambiguity).
  9. We can use multiple inheritance to model the concept of roles. For example, for subclasses, student, teacher and footballPlayer, an object can belong to several categories at once and each of these categories is called a role. We can use multiple inheritance to create subclasses, such as student-teacher, student-footballPlayer, and so on to model the possibility of an object simultaneously having multiple roles.


next up previous
Next: Object Identity Up: The Object-Oriented Data Model Previous: Inheritance

Osmar Zaiane
Mon Jun 29 17:30:13 PDT 1998