A class diagram shows:
Components and Structure
We will use the Unified Modeling Language (UML) for class diagrams. Figure 1 shows the major components of a UML class diagram:
As shown in Figure 2, an association may contain various adornments. An association role is simply the end of an association where it connects to the class. Each end of an association is a role. A role is a part of the association, not part of the class. The association path may have graphical adornments on each end to specify properties of the role.
The adornments are:
An association name to clarify the meaning of the association. An arrow may be used to indicate the direction to which the name applies.
A single number or a set of numbers to indicate the allowable cardinalities that the set of associations may assume. Intervals may be included in the set. An asterisk is used to represent an unlimited number. For example:
||zero or one|
||zero or more|
||two or more|
||either zero or four|
||either zero or four or more|
If the association multiplicity is greater than one, then the set of associations may be ordered or unordered based on some property of the association or the attached object. Ordering types are:
An arrow may be attached to the end of the path to indicate that navigation is supported toward the class attached to the arrow. Navigability is often not specified in analysis models; navigation is assumed to be in both directions. Part of converting an analysis model into a design model is to determine if navigation must be supported in both directions.
A hollow diamond indicates that an instance of the class attached to the diamond aggregates instances of the class at the other end of the association. A filled diamond may be used to indicate a stronger form of aggregation known as composition. A diamond may not be attached to both ends of the line.
A name may be attached near the end of the path to indicate the role played by an instance of the class attached to that end. Rolenames are optional.
An association may have its own attributes.
These attributes exist only if an instance of the
This is illustrated in Figure 3.
The attributes salary and jobTitle
exist only if there is an instance of a Works-for association
between a Person and a Company.
If the association also has behavior, then the association
has all of the properties of a class.
This is illustrated in the next diagram were the association attributes
have been promoted to an association class named Job that has
an operation that allows the salary to be changed.
The following figure is an example of a class diagram:
You would read this model as follows:
A Building is owned by one Person. A Person may own more than one building, but based on the navigation arrow, a Person does not know about those buildings. Each Building is either a House or an Apartment. An Apartment contains two or more RentalUnits.The model also shows some attributes for each object but the attributes were not included in the discussion.
It is possible to Buy a House or an Apartment, and Rent or Vacate a RentalUnit.
This next model shows aggregation and association:
In the figure, a company is an aggregate of divisions which is an aggregate of departments. But a person is associated with the company as an employee and also with a department through an assignment. The division depends on the company for its existence. But the association between a person and a department can change.
Prepared by David L. March -- Last Revised on October 1, 2001
COPYRIGHT © 1998-2001 BY DAVID L. MARCH