UML Class Diagram Association

UML association is a kind of connector in the class diagram which specifies how are the particular classes related to each other.

Association Navigability

The associations in class diagrams can be navigable in various directions. The navigability is depicted using the arrows on the connector ends.

Various navigabilities of UML associations
Various navigabilities of UML associations

The picture shows the following combinations of the navigability between associations:

  • Unspecified navigability - there is an association between Class1 a Class2, but the navigability is unknown or irrelevant. The association is depicted as a simple undecorated connector.
  • Navigable in one direction - the association can be navigated from Class3 to Class4, but not from Class4 to Class3 (in a direct way). In code, it means there is a field of the Class4 type that is defined within the Class3 class. The association is depicted as a connector with an arrow on one end.
  • Navigable in both directions - the association can be navigated from Class5 to Class6 and also from Class6 to Class5. In code, it means there is a field of the Class6 type defined within the Class5 class and a field of Class5 type defined within the Class6 class. The association is depicted as a connector with arrows on both ends.
  • Navigable in one direction (explicit) - the association can be navigated from Class7 to Class8, but not from Class8 to Class7 (in a direct way). This notation explicitly shows that the opposite navigation is not allowed. The association is depicted as a connector with a diagonal cross on one side and an arrow on the other side.
  • Non-navigable - the association cannot be navigated in any direction, neither from Class9 to Class10 nor from Class10 to Class9. In code, it means the fields representing this association are not defined in either of these two classes. The non-navigable association expresses an indirect relationship between two classes which we want to emphasize in the model (e.g. it may be a relationship via a hash). The association is depicted as a connector with diagonal crosses on both sides.

Association Navigability with Class Ownership

The class ownership of the association end is depicted using the dot on the side of the class that owns the attribute (of the association end).

UML associations with specified navigability and ownership
UML associations with specified navigability and ownership

There are other possible combinations of association ends using the dot notation:

  • Class-owned on one side (navigable in one direction) - the ClassA class owns the attribute 'b' of the ClassB type. The association owns the 'a' attribute. The association is navigable only in one direction from ClassA to ClassB.
  • Class-owned on both sides (explicitly navigable) - the ClassC class owns the attribute 'd' of the ClassD type and the ClassD class owns the attribute 'c' of the ClassC class. The association is navigable in both directions which are explicitly depicted using the arrowed connector.
  • Class-owned on both sides (implicitly navigable) - the ClassE class owns the attribute 'f' of the ClassF type and the ClassF class owns the attribute 'e' of the ClassE class. The association is navigable in both directions in principle. The navigability is not emphasized with the depicted arrows.
  • Class-owned on one side (navigable in both directions) - the ClassG class owns the attribute 'h' of the ClassH type. The association owns the 'g' attribute. The association is navigable in both directions.
  • Class-owned on one side (explicitly non-navigable) - the ClassI class owns the attribute 'j' of the ClassJ type. The association owns the 'i' attribute. The association is navigable only in one direction from ClassI to ClassJ. There is not any field in the ClassJ class that would allow navigating to ClassI. The non-navigable direction is marked with the diagonal cross cap.

Association Cardinality

The association ends can have various cardinalities:

  • One
  • Zero or one
  • Zero to many
  • One to many
  • Many
  • A specific number
  • A specific range of numbers
UML associations with various cardinalities
UML associations with various cardinalities

The picture shows to following cardinalities between classes:

  • class A has associated multiple instances of class B, the class B has associated a single instance of class A.
  • class C has associated zero or more instances of class D, the class D has associated a single instance of class C.
  • class E has associated one or more instances of class F, class F has associated a single instance of class E.
  • the class G has associated exactly one instance of the class H, the class H has also associated only one instance of the class G.
  • the class I has associated none or one instance of the class J, the class J has associated a single instance of class I.

New Comment

Comment