Subclasses in ODL / Multiple Inheritance in ODL

Subclasses in ODL / Multiple Inheritance in ODL

Subclasses in ODL

Let us remember the discussion of subclasses in the E/R model from "Subclasses in the E/R Model". There is a similar capability in ODL to declare one class C to be a subclass of another class D. We follow the name C in its declaration with the keyword extends and the name D.

Example (a) : Recall "Subclasses in the E/R Model" Example (a), where we declared cartoons to be a subclass of movies, with the additional property of a relationship from a cartoon to a set of stars that are its "voices". We can create a subclass Cartoon for Movie with the ODL declaration:

We have not pointed out the name of the inverse of relationship voices, though technically we must do so.

A subclass inherits all the properties of its superclass. Hence, each cartoon object has attributes title, year, length and filmType inherited from Movie (recall "Relationships in ODL / Inverse Relationships" Figure (a)), and it inherits relationships stars and ownedBy from Movie, in addition to its own relationship voices.

Also in that example, we described a class of murder mysteries with additional attribute weapon.

is a suitable declaration of this subclass. Again, all the properties of movies are inherited by MurderMystery.

Multiple Inheritance in ODL

Sometimes, as in the case of a movie like "Roger Rabbit", we need a class that is a subclass of two or more other classes at the same time. In the E/R model we were able to imagine that "Roger Rabbit" was represented by components in all three of the Movies, Cartoons, and Murder-Mysreries entity sets, which were connected in an isa-hierarchy. However, a principle of object-oriented systems is that objects belong to one and only one class. Therefore, to represent movies that are both cartoons and murder mysteries, we need a fourth class for these movies.

The class CartoonMurderMystery must inherit properties from both Cartoon and MurderMystery, as suggested by following Figure (a). That is, a CartoonMurderMystery object has all the properties of a Movie object, plus the relationship voices and the attribute weapon.

Diagram showing multiple inheritance

In ODL, we may follow the keyword extends by various classes, separated by colons. Therefore, we may declare the fourth class by:

When a class C inherits from various classes, there is the potential for conflicts among property names. Two or more of the superclasses of C may have a property of the same name, and the types of these properties may vary. Class CartoonMurderMystery did not present such a problem, since the only properties in common between Cartoon and MurderMystery are the properties of Movie, which are the same property in both superclasses of CartoonMurderMystery. Here is an instance where we are not so lucky.

Example (b) : Assume we have subclasses of Movie called Romance and Courtroom. Further assume that each of these subclasses has an attribute called ending. In class Romance, attribute ending draws its values from the enumeration {happy, sad}, while in class Courtroom, attribute ending draws its values from the enumeration {guilty, notGuilty}. If we create a further subclass, Courtroom-Romance, that has as superclasses both Romance and Courtroom, then the type for inherited attribute ending in class Courtroom-Romance is unclear.

The ODL standard does not state how such conflicts are to be resolved. Some possible approaches to handling conflicts that arise from multiple inheritance are:

1.  Disallow multiple inheritance altogether. This approach is usually regarded as too limiting.

2. Indicate which of the candidate definitions of the property applies to the subclass. For instance, in above Example (b) we may decide that in a courtroom romance we are more interested in whether the movie has a happy or sad ending than we are in the verdict of the courtroom trial. In this case, we would state that class Courtroom-Romance inherits attribute ending from superclass Romance, and not from superclass Courtroom.

3. Give a new name in the subclass for one of the identically named properties in the superclasses. For instance, in above Example (b), if Courtroom-Romance inherits attribute ending from superclass Romance, then we may state that class Courtroom-Romance has an additional attribute called verdict, which is a renaming of the attribute ending inherited from class Courtroom.