Additional ODL Concepts

Additional ODL Concepts

There are many other features of ODL that we must study if we are to express in ODL the things that we can express in the E/R or relational models. In this section, we shall cover:

1. Representing multiway relationships. Notice that all ODL relationships are binary, and we have to go to some lengths to represent 3-way or higher arity relationships that are simple to represent in E/R diagrams or relations.

2. Subclasses and inheritance.

3. Keys, which are optional in ODL.

4. Extents, the set of objects of a given class that exist in a database. These are the ODL equivalent of entity sets or relations, and must not be confused with the class itself, which is a schema.

Multiway Relationships in ODL

ODL supports only binary relationships. There is a trick, which we introduced in "Multiway Relationships", to replace a multiway relationship by several binary, many-one relationships. Assume we have a multiway relationship R among classes or entity sets C1, C2, . . . , Cn. We may replace R by a class C and n many-one binary relationships from C to each of the Ci's. Each object of class C  may be thought of as a tuple t in the relationship set for R. Object t is related, by the n many-one relationships, to the objects of the classes Ci that participate in the relationship-set tuple t. 

Example : Let us consider how we would represent in ODL the 3-way relationship Contracts, whose E/R diagram was given in "Attributes on Relationships" Figure. We may start with the class definitions for Movie, Star, and Studio, the three classes that are related by Contracts, that we saw in "Relationships in ODL / Inverse Relationships" Figure (a).

We must make a class Contract that corresponds to the 3-way relationship Contracts. The three many-one relationships from Contract to the other three classes we shall call theMovie, theStar, and theStudio. The following Figure (a) shows the definition of the class Contract.

A class Contract to represent the 3-way relationship Contracts

There is one attribute of the class Contract, the salary, since that quantity is associated with the contract itself, not with any of the three participants. Recall that in "Attributes on Relationships" Figure we made a similar decision to place the attribute salary on the relationship Contracts, rather than on one of the participating entity sets. The other properties of Contract objects are the three relationships mentioned.

Note that we have not named the inverses of these relationships. We need to change the declarations of Movie, Star, and Studio to include relationships from each of these to Contract. For example, the inverse of theMovie might be named contractsFor. We would then replace line (3) of Figure (a) by

3)      relationship Movie theMovie
                inverse Movie: :contractsFor;

and add to the declaration of Movie the statement:

          relationship Set contractsFor
                 inverse Contract: :theMovie;

Notice that in Movie, the relationship contractsFor gives us a set of contracts, since there may be various contracts associated with one movie. Each contract in the set is basically a triple consisting of that movie, a star, and a studio, plus the salary that is paid to the star by the studio for acting in that movie.