Attributes in ODL

Attributes in ODL

The simplest type of property is the attribute. These properties explain some feature of an object by connecting a value of a fixed type with that object. For instance, person objects might each have an attribute name whose kind is string and whose value is the name of that person. Person objects might also have an attribute birthdate that is a triple of integers (i.e., a record structure) standing for the year, month, and day of their birth.

In ODL, unlike the E/R model, attributes need not be of simple kinds, such as integers and strings. We just talked about birthdate as an instance of an attribute with a structured type. For another instance, an attribute such as phones might have a set of strings as its type, and even more complicated kinds are possible. We summarize the type system of ODL in "Types in ODL".

Example (a): In the following figure (a). is an ODL declaration of the class of movies. It is not a complete declaration; we shall add more to it later. Line (1) declares Movie to be a class. Following line (1) are the declarations of four attributes that all Movie objects will have.

An ODL declaration of the class Movie

The first attribute, on line (2), is named title. Its type is staring - a character string of unknown length. We expect the value of the title attribute in any Movie object to be the name of the movie. The next two attributes, year and length declared on lines (3) and (4), have integer type and represent the year in which the movie was made and its length in minutes, respectively. On line (5) is one more attribute filmType, which tells whether the movie was filmed in color or black-and-white. Its type is an enumeration, and the name of the enumeration is Film. Values of enumeration attributes are chosen from a list of literals, color and blackAndWhite  in this instance.

An object in the class Movie as we have defined it so far can be thought of as a record or tuple with four elements, one for each of the four attributes.

For instance,

("Gone With the Wind",1939, 231, color)

is a Movie object.

Example (b): In Example (a), all the attributes have atomic types. Here is an example with a nonatomic type. We can describe the class Star by


Line (2) specifies an attribute name (of the star) that is a string. Line (3) specifies another attribute address. This attribute has a type that is a record structure. The name of this structure is Addr, and the type comprises two fields: street and city. Both fields are strings. Generally, one can describe record structure types in ODL by the keyword Struct and curly braces around the list of field names and their types. Like enumerations, structure types must have a name, which can be used elsewhere to refer to the same structure type.

Why Name Enumerations and Structures