4.3.  Relationships

[ fromfile: relationships.xml id: relationships ]

When there is a one-to-one or a one-to-many correspondence between objects of certain types, we use a variety of connecting lines to describe a relationship between them in a UML class diagram.

Figure 4.1.  One-To-Many Relationship

One-To-Many Relationship

In Figure 4.1, the line connecting the classes is the relationship.

In the “world” specified by this diagram, there can be many Person instances working for exactly one Employer. This can be determined by the multiplicity specifier at each end of the relationship: 1 at the Employer end, and * at the Person end. The * takes on its regular expression definition, of “0 or more”. (Section 13.3).

Revisiting Figure 2.6, another set of relationships is revealed when we look at the company from the Employer's viewpoint. Figure 4.2 shows three kinds of relationships.

Figure 4.2.  The Employer's view of the Company

The Employer's view of the Company

  1. There is a composition relationship between Employer and Position. It indicates that the Employer owns or manages the Position, and the Position should not exist without the Employer.

  2. There is an aggregate relationship (the hollow diamond) from the Employer to its employees. The Employer groups together a collection of Persons and gets them to do things during working hours. In an aggregate relationship, the lifetimes of the objects on either end are not related to each other.

  3. The Person and the Position have an assocation between them. An association is a bidirectional relationship, and does not specify anything about ownership or management between objects. Although our diagram indicates a 1:1 relationship between them, it is possible that other Employers may hire many Persons for the same Position. In such a case, the numbers should reflect that in the diagram.