uOttawaUniversity of Ottawa - Canadas University
list of dots

Umple User Manual    [Next]   


Association Definition

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.

UML class diagram showing classes A, B and C with several associations

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 27 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 an association refers to a non-existent class.


// Example code illustrating various
// kinds of associations
class A {}

// Class with inline association having role name
class B {
  1 -- * A endTwo; 

// Class with reflexive association
class C {
  0..1 -- * C;
  1 -- 0..1 D; // D is external

// Independently defined and directed association
association {
  0..1 A -> * C;

// Class with composition
class E {
  0..1 e <@>- * A a;

// Reference to a class defined elsewhere
external D {}

Load the above code into UmpleOnline