An association defines a relationship from a class to another class. More specifically, it defines which links (i.e. references or pointers) may exist at run time between instances of the classes.
Umple supports binary associations (associations with just two ends). This definition includes reflexive associations, in which both ends are the same class.
An association can specify the following information:
- The classes involved (i.e. one or two classes).
- Navigability: -- means both ways (i.e. each class can access the linked objects of the other class) and -> means one way.
- The restrictions on the number of objects allowed in the relationship (multiplicity).
- Role names on association ends (to clarify the relationship and avoid collision if two classes are associated in multiple ways).
The following is a UML diagram showing associations. The corresponding Umple is at the end of the page.
Associations can be presented in two ways in Umple.
- Inline - Defined within one of the associated classes. See line 7 of the example below; the association is defined between A and B.
- Independently - defined as a first-class entity in the model. See line 18 of the example below; the association is defined between A and C.
There are several special kinds of associations in Umple.
- Reflexive - A class that is associated with itself. See line 12 of the example below; the association is defined between C and itself.
- Compositions - A composition is a sub-type of association where there is mandatory delete on the composition end, regardless of the multiplicity.
- External - To associate a class to class in non-umple code. See lines 13 and 22 of the example below; the association is defined between C and a class D that doesn't appear in this model and is shown as an external reference. Class D must be separately linked in; it could also be generated by Umple or could be hand-written. For more on the use of the external keyword, see this example.
- Association Class - A shorthand for two one-to-many associations to a class
that contains data that relates the two classes. The two related classes are
logically in a many-many relationship (this is currently under development).
Umple will report an error if the an association refers to a non-existent class.