4.2. Modeling EntityTypes as Classes

The main building blocks of UML class diagrams are class rectangles and association lines. In a conceptual information model, a class rectangle has one or two compartments, containing the name of the class and its attributes.

An entity type can be modelled as a UML class. For instance, the entity type movies, with attributes title, release date and director, can be modeled as shown in Figure 4-1.

Figure 4-1. The entity type movies represented as a class.

Notice that, in a conceptual model, we choose English noun phrases in plural form (such as "movies" or "tv series") as the names of classes and singular or plural noun phrases as the names of attributes. A plural name of an attribute indicates that it is multi-valued.

At any point in time, a class representing an entity type has a set of instances that form its extension, which can be shown in the form of a table such that each table row represents an instance of the class (a particular entity). In the case of the class movies, the following table could represent its extension:

Table 4-1. movies
titlerelease datedirector
Pulp Fiction1994-05-12Quentin Tarantino
Star Wars1977-05-25George Lucas
Dangerous Liaisons1988-12-16Stephen Frears

Multi-Valued Attributes

An attribute of an entity type may have more than one value. For instance, since a movie may belong to more than one genre, an attribute for holding this information would be called genres, and for "Star Wars" it would hold the value set {Action, Adventure, Fantasy, Sci-Fi}.

While the plural form of an attribute's name already indicates that it is multi-valued, this is formally expressed by the attribute's multiplicity 1..*, which defines 1 as the minimum cardinality of the attribute's value set and * (standing for unbounded) as its maximum cardinality, as shown in Figure 4-2.

Figure 4-2. The entity type "movies" with a multi-valued attribute "genres".

Notice that all other attributes have the multiplicity 1, which stands for exactly one value.

Optional Attributes

By default, an attribute in a UML class diagram is mandatory, that is, it must have a value. This may be explicitly expressed for a single-valued attribute by appending the multiplicity expression 1..1, or simply 1, standing for "exactly one", enclosed in brackets, to the attribute's name or range, like birthDate[1].

When a single-valued attribute is optional, this must be designated in a class diagram with the multiplicity expression 0..1, as shown in Figure 4-3 below.

Consider the entity type people modeled with the two attributes birth date and death date in Figure 4-3. All instances of people must have a value for the attribute birth date, so it is mandatory. But this does not apply to the attribute death date, since for all people that are still alive, there is no value for it. Consequently, death date is an optional attribute.

Figure 4-3. The attribute "birth date" is mandatory, while "death date" is optional..