Low Level Design

UML Class Diagrams: The Ultimate Guide

A concise guide to the core relationships in UML Class Diagrams: Association, Aggregation, Composition, Inheritance, Realization, and Dependency, with clear definitions and real-world examples.

December 18, 2025

UML Class Diagrams serve as the blueprint for system design, mapping out the static structure of an application. The true power of these diagrams lies not just in the classes themselves, but in how they connect to one another. These connections, or relationships, define the rules of interaction and dependency between objects.

Mastering these relationships—ranging from simple association to strict composition—is essential for building modular and scalable systems. Here is a breakdown of the key relationships you need to know.

UML Diagram

1. Association#

"Uses-a" Relationship

Association describes a general relationship between two classes where one class uses or interacts with the other. It implies that two objects know about each other and work together.

Example: A Car interacts with a Driver. The Car class uses or references the Driver class to function, but they are separate entities.

2. Aggregation#

"Has-a" Relationship (Weak / Loose Coupling)

Aggregation is a specialized form of association that represents a "whole-part" relationship. Crucially, the "part" can exist independently of the "whole". If the parent object is destroyed, the child object survives.

Example: A Car has an Engine. While an engine is part of a car, the Engine can exist on its own (e.g., in a repair shop) without the Car.

3. Composition#

"Has-a" Relationship (Strong / Strict Coupling)

Composition is a stricter form of aggregation. Here, the "part" cannot exist without the "whole". The lifecycle of component objects is managed strictly by the parent object. If the container is destroyed, the contents are destroyed with it.

Example: A House is composed of Rooms. If you demolish the House, the Room objects cease to exist. A room cannot float in isolation without a house.

4. Inheritance#

"Is-a" Relationship (Generalization)

Inheritance establishes a hierarchy where one class (the subclass) inherits attributes and methods from another (the superclass). It promotes code reuse and logical hierarchy.

Example: Dog and Cat are both subclasses of Animal. They inherit common traits (like eat() or sleep()) from Animal but can have their own unique behaviors.

5. Realization (Implementation)#

"Can-do" Relationship

Realization defines a contract between a class and an interface. The class "realizes" or implements the methods promised by the interface.

Example: Rectangle and Circle both implement the Shape interface. The Shape interface demands a getArea() method, and both classes must provide their own specific logic for it.

6. Dependency#

"Uses-temporarily" Relationship

Dependency is the weakest relationship. It implies that one class relies on another at a specific point in time (like in a method call). A structural change in the "supplier" class might affect the "client" class.

Example: A Customer places an Order. The Customer class depends on the Order class only for the duration of that transaction.