Class Diagram – Relationships

Posted By on April 29, 2016

Download PDF
Class Diagram
Interaction Diagram

A relationship is a general term covering the specific types of logical connections found on class and object diagrams.

UML shows the following relationships:

Instance-level relationships:-


  • A dependency is the basic relationship among objects.


  •  Class diagram example of association between two classes
  • An association represents a family of links.
  • A binary association (with two ends) is normally represented as a line.
  • An association can link any number of classes.
  • An association with three links is called a ternary association.
  • An association can be named, and the ends of an association can be adorned with role names, ownership indicators, multiplicity, visibility, and other properties.
  • There are four different types of association: bi-directional, uni-directional, aggregation (includes composition aggregation) and reflexive.
  • Bi-directional and uni-directional associations are the most common ones.

For instance, a flight class is associated with a plane class bi-directionally. Association represents the static relationship shared among the objects of two classes.


  • Class diagram showing Aggregation between two classes
  • Aggregation is a variant of the “has a” association relationship; aggregation is more specific than association.
  • It is an association that represents a part-whole or part-of relationship.
  • As shown in the image, a Professor ‘has a’ class to teach.
  • As a type of association, an aggregation can be named and have the same adornments that an association can.
  • However, an aggregation may not involve more than two classes; it must be a binary association.
  • Furthermore, there is hardly a difference between aggregations and associations during implementation, and the diagram may skip aggregation relations altogether.
  • Aggregation can occur when a class is a collection or container of other classes, but the contained classes do not have a strong lifecycle dependency on the container.
  • The contents of the container are not automatically destroyed when the container is.
  • In UML, it is graphically represented as a hollow diamond shape on the containing class with a single line that connects it to the contained class.
  • The aggregate is semantically an extended object that is treated as a unit in many operations, although physically it is made of several lesser objects.

Example: Library has Students and books. Here the student can exist without library, the relation between student and library is aggregation.


  •  Class diagram showing Composition between two classes at top and Aggregation between two classes at bottom
  • Composition is a stronger variant of the “has a” association relationship; composition is more specific than aggregation.
  • Composition usually has a strong lifecycle dependency between instances of the container class and instances of the contained class(es): if the container is destroyed, normally every instance that it contains is destroyed as well.
  • Where allowed, a part can be removed from a composite before the composite is deleted, and thus not be deleted as part of the composite.
  • The UML graphical representation of a composition relationship is a filled diamond shape on the containing class end of the tree of lines that connect contained class(es) to the containing class.

Differences between composition and aggregation

Composition relationship: When attempting to represent real-world whole-part relationships, e.g. an engine is a part of a car.
Aggregation relationship: When representing a software or database relationship, e.g. car model engine ENG01 is part of a car model CM01, as the engine, ENG01, may be also part of a different car model.
Thus the aggregation relationship is often “catalog” containment to distinguish it from composition’s “physical” containment.

Class-level relationships


  •  Class diagram showing generalization between the superclass Person and the two subclasses Studentand Professor
  • It indicates that one of the two related classes (the subclass) is considered to be a specialized form of the other (the super type) and the superclass is considered a Generalization of the subclass.
  • In practice, this means that any instance of the subtype is also an instance of the superclass.
  • An exemplary tree of generalizations of this form is found in biological classification: humans are a subclass of simian, which is a subclass ofmammal, and so on. The relationship is most easily understood by the phrase ‘an A is a B’ (a human is a mammal, a mammal is an animal).
  • The UML graphical representation of a Generalization is a hollow triangle shape on the superclass end of the line (or tree of lines) that connects it to one or more subtypes.
  • The generalization relationship is also known as the inheritance or “is a” relationship.
  • The superclass (base class) in the generalization relationship is also known as the “parent”, superclass, base class, or base type.
  • The subtype in the specialization relationship is also known as the “child”, subclass, derived class, derived type, inheriting class, or inheriting type.
  • Generalization can only be shown on class diagrams and on use case diagrams.

Class Diagram
Interaction Diagram

Download PDF

Posted by Akash Kurup

Founder and C.E.O, World4Engineers Educationist and Entrepreneur by passion. Orator and blogger by hobby