Association, Aggregation and Composition

 

The association link indicates that two classes have a relationship: a student attends a school; a student takes courses.

 

 

How do I set up an association?

 

Each association link has two ends which are called roles.  Each role has a name, a multiplicity, a navigability and a type.

Multiplicity:

The multiplicity of a role indicates how many objects can participate in the relationship.  In the example above, a school has many students and each student attends only one school.

Navigability:

Sometimes a role has an arrow indicating its navigability.  This shows which class has the responsibility for maintaining the relationship between the classes.  In the example above, the school class has a responsibility for knowing which students attend.  Therefore, you don't have to explicitly define a getStudents operation in the school class (although you may) since it is already implicitly defined by the navigability of the association.

Type:

The role can have one of three types: association, composition or aggregation.  Associations indicate that the two classes have a relationship as discussed above.  Composition and aggregation indicate something more about the relationship:

 

Composition indicates that one class belongs to the other.  A polygon is made up of several points.  If the polygon is destroyed, so are the points.

 

Aggregation is similar to composition, but is a less rigorous way of grouping things.  An order is made up of several products, but a product continues to exist even if the order is destroyed.

 

In Visual Case, there are icons in the class diagram toolbar to allow you to draw an association, composition or aggregation link directly onto your diagram.  However, once the link is drawn, you can change either role type to any of three possible values.

 

Related Topics: