Problem Analysis  «Prev  Next»
Lesson 7 Class diagram Associations
Objective Review the class diagram notation.

Class Diagram Associations

A class can communicate only with another class it knows about, for instance, a class with which it is associated. To associate classes, use a line between two classes adorned with some qualifying elements.

Naming Associations

Remember how parts of speech map to elements in the models? Every association needs a name, an active verb that describes the relationship of one class to another class, such as "owns" or "opens."

Multiplicity Defined

A number of objects of each class may be associated. For example, a customer may open many accounts, and an order may include many items. The number of participating objects is called the multiplicity, and it must be set for each end of the association.
The notation for multiplicity is as follows:
  1. Asterisk (*) when used alone means zero or more, no lower or upper limit.
  2. Asterisk (*) when used in a range (1..*) means no upper limit.
  3. Values separated by two periods (..) mean a range.
  4. Values separated by commas mean an enumerated list of values.
An association describes discrete connections among objects or other instances in a system. An association relates an ordered list (tuple) of two or more classifiers, with repetitions permitted. The most common kind of association is a binary association between a pair of classifiers. An instance of an association is a link. A link comprises a tuple (an ordered list) of objects, each drawn from its corresponding class. A binary link comprises a pair of objects. Associations carry information about relationships among objects in a system. As a system executes, links among objects are created and destroyed. Associations are the "glue" that ties a system together. Without associations, there are nothing but isolated classes that don’t work together. A single object may be associated with itself if the same class appears more than once in an association. If the same class appears twice in an association, the two instances do not have to be the same object, and usually they are not. Each connection of an association to a class is called an association end. Most information about an association is attached to one of its ends. Association ends can have role-names and visibility. The most important property they have is multiplicity, which is how many instances of one class can be related to one instance of the other class. Multiplicity is most useful for binary associations because its definition for n-ary associations is complicated. If the multiplicity upper bound is greater than one, the ordering and uniqueness of associated values may be specified on an association end.

Class associations
Class associations

Roles and constraints

When an association name is difficult to define, roles provide an alternative. A role name such as "supervisor" may be placed on one or both ends of the association. Finally, you can add constraints using the standard notation. Place the constraint on the end of the association being constrained. In this example, you see two classes, Customer and Order. A customer may place zero or more orders, but an order cannot exist unless a customer places it. The customers placing the orders are preferred customers only. The orders they place are priority orders. The role names clarify the interpretation of the association between the two classes.

Customer elements in Class diagram
  1. Role: Must have a name or roles or both
  2. Association name: Must have a name or roles or both
  3. Role: Must have a name or roles or both
  4. Class
  5. Constraint: Optional
  6. Multiplicity: Required
  7. Association
  8. Multiplicity: Required
  9. Class