UML relations for class diagrams, everything you need to know

Thomas
3 min readNov 29, 2020

--

There are multiple types of UML relations in a class diagram. Here is a list, which shows how and when to use different relations with short examples.

Association

An association is a relationship, where 2 components interact with each other in some way, but are not dependent or related with each other. For example an author writes a book. A User opens a door. A student writes a test.

You can also write an association with a cardinality. For a example a student has multiple tests and a test has multiple students.

Dependency

A dependency relationship says that component A relates somehow with component B. It is a bit tricky, because it can mean multiple different relations [https://www.uml-diagrams.org/dependency.html].

There are 2 important types of dependencies in UML Class diagrams:

  • use

▹create

▹call

▹send

  • abstraction

▹ realization

Although realization has a different arrowhead than general dependency, it is also a type of dependency relationship. A realization is for example a class, which realizes an interface.

Composition

Component A depends on component B. For example a bullet point on a list can’t exist without that list. When you delete component B, A also gets deleted.

Aggregation

Component B has multiple components A. But when you delete component B, A still exists.

Example: A football team has multiple players. When the team gets dissolved, then the players still exist and may want to apply to other teams.

Generalization

Generalization is when a component inherits from another component. For example horse inherits from animal. The difference between generalization and realization is like inheritation and implementation, simplified.

--

--