Association Relationships in UML Class Diagrams
Association relationships in UML Class Diagrams describe how objects are related and interact within a system. This section explores various types of associations and how they are represented in UML.
Basic Association
An association represents a "has-a" relationship between classes, typically depicted as a solid line. For example, a Course
having an Instructor
can be represented as:
Multiplicity in Associations
Multiplicity indicators specify the number of instances of one class related to one instance of the other class. For instance:
-
A
Course
has exactly oneInstructor
: -
An
Instructor
can teach one or moreCourses
:
Role Names and Association Names
Role names clarify the function of each class in the association. Associations can also be named to further describe the relationship.
-
Role Names:
-
Association Names:
Multiple Associations and Navigability
Classes can have more than one type of association. Navigability, indicated by an arrow, shows the direction in which methods can invoke the other class.
-
Multiple Associations:
-
Navigability:
Self-Association
A class can have a relationship with itself, known as self-association.
Aggregations and Compositions
-
Aggregation (hollow diamond) indicates a whole-part relationship where parts can exist independently:
-
Composition (filled diamond) implies strong ownership, where parts cannot exist without the whole: