Class Diagram Relationships in UML With Examples
Class Diagram Relationships in UML With Examples
Class Diagram Relationships in UML With Examples
com/blog/)
banner&utm_medium=blog&utm_campaign=Increase%20Blog%20Signups)
Hide this ()
Many people consider class diagrams a bit more complicated to build compared with ER
diagrams. Most of the time it’s because of the inability to understand the different
relationships between class diagram. This article explains how to correctly determine
and implement the different class diagram relationships that are applicable in object-
oriented modeling. What’s more, you can easily create class diagrams
(https://creately.com/diagram-type/class-diagram?
utm_source=classrelationships&utm_medium=blog&utm_campaign=tutorialposts)
using our diagramming tool.
(https://d3n817fwly711g.cloudfront.net/blog/wp-
content/uploads/2012/03/Class-Diagram-Relationships.png)
Relationships in UML class diagrams
(https://d3n817fwly711g.cloudfront.net/blog/wp-
content/uploads/2012/03/Class-
Diagram.jpeg)
Simple class diagram with attributes and
operations
In the example, a class called “loan account” is depicted. Classes in class diagrams are
represented by boxes that are partitioned into three:
The example shows how a class can encapsulate all the relevant data of a particular
object in a very systematic and clear way. A class diagram is a collection of classes
similar to the one above.
Association
Directed Association
Re exive Association
Multiplicity
Aggregation
Composition
Inheritance/Generalization
Realization
Association
(https://d3n817fwly711g.cloudfront.net/blog/wp-
content/uploads/2012/03/Association-
Relationship.jpeg)
Association
is a broad term that encompasses just about any logical connection or relationship
between classes. For example, passenger and airline may be linked as above:
Directed Association
(https://d3n817fwly711g.cloudfront.net/blog/wp-
content/uploads/2012/03/Directed-
Association-
Relationship.jpeg)
Directed Association
Re exive Association
(https://d3n817fwly711g.cloudfront.net/blog/wp-
content/uploads/2012/03/Re exive-
Association-
Relationship.jpeg)
Re exive Association
This occurs when a class may have multiple functions or responsibilities. For example, a
staff member working in an airport may be a pilot, aviation engineer, a ticket dispatcher, a
guard, or a maintenance crew member. If the maintenance crew member is managed by
the aviation engineer there could be a managed by relationship in two instances of the
same class.
Multiplicity
(https://d3n817fwly711g.cloudfront.net/blog/wp-
content/uploads/2012/03/Multiplicity-
Relationship.jpeg)
Multiplicity
is the active logical association when the cardinality of a class in relation to another is
being depicted. For example, one eet may include multiple airplanes, while one
commercial airplane may contain zero to many passengers. The notation 0..* in the
diagram means “zero to many”.
Aggregation
(https://d3n817fwly711g.cloudfront.net/blog/wp-
content/uploads/2012/03/Aggregation-
Relationship.png)
Aggregation
refers to the formation of a particular class as a result of one class being aggregated or
built as a collection. For example, the class “library” is made up of one or more books,
among other materials. In aggregation, the contained classes are not strongly dependent
on the lifecycle of the container. In the same example, books will remain so even when
the library is dissolved. To show aggregation in a diagram, draw a line from the parent
class to the child class with a diamond shape near the parent class.
To show aggregation in a diagram, draw a line from the parent class to the child class
with a diamond shape near the parent class.
Composition
(https://d3n817fwly711g.cloudfront.net/blog/wp-
content/uploads/2012/03/Composition-
Relationship-
UML.png)
Composition
The composition relationship is very similar to the aggregation relationship. with the only
difference being its key purpose of emphasizing the dependence of the contained class
to the life cycle of the container class. That is, the contained class will be obliterated
when the container class is destroyed. For example, a shoulder bag’s side pocket will
also cease to exist once the shoulder bag is destroyed.
Inheritance / Generalization
(https://d3n817fwly711g.cloudfront.net/blog/wp-
content/uploads/2012/03/Inheritance-
Relationship.jpeg)
Inheritance
Realization
(https://d3n817fwly711g.cloudfront.net/blog/wp-
content/uploads/2012/03/Realization-
Relationship.jpeg)
Realization
denotes the implementation of the functionality de ned in one class by another class. To
show the relationship in UML, a broken line with an un lled solid arrowhead is drawn
from the class that de nes the functionality to the class that implements the function. In
the example, the printing preferences that are set using the printer setup interface are
being implemented by the printer.
Drawing from scratch can be cumbersome. You can get started immediately using our
professionally designed class diagrams. Browse our class diagram templates
(https://creately.com/diagram-type/templates/class-diagram?
utm_source=classrelationships&utm_medium=blog&utm_campaign=tutorialposts) and
pick the one that’s closely related to your system.
References: