Fundamentals 8 min read

Mastering UML: The Six Core Relationships Every Developer Should Know

UML class diagrams feature six primary relationships—Generalization, Realization, Dependency, Association, Aggregation, and Composition—each with distinct visual notations and semantics, and this guide explains their definitions, code representations in Java, and practical examples to help developers model system structures accurately.

ITFLY8 Architecture Home
ITFLY8 Architecture Home
ITFLY8 Architecture Home
Mastering UML: The Six Core Relationships Every Developer Should Know

UML’s Six Major Relationships

In UML class diagrams, the common relationships are Generalization, Realization, Association, Aggregation, Composition, and Dependency.
1.1 Generalization (Inheritance) Generalization denotes that a subclass (or sub‑interface) inherits the features of a superclass (or super‑interface) and can add new functionality. In Java it is expressed with the extends keyword. The arrow is a solid line with a closed triangular head pointing to the parent class.
1.2 Realization Realization describes a class implementing one or more interfaces. In Java this relationship is marked with the implements keyword. The arrow is a dashed line with a closed triangular head pointing to the interface.
1.3 Dependency A dependency is a weak, temporary usage relationship where one class (A) uses another class (B). Changes in B may affect A. In code this appears as method parameters, local variables, or static method calls. The arrow is a dashed line with an open arrowhead pointing to the used class.
1.4 Association Association is a stronger, long‑term relationship where two classes know each other’s attributes and methods. It can be unidirectional or bidirectional and is represented in code by member variables. Bidirectional association uses two arrows or a line without arrows; unidirectional uses a single arrow.
1.4.1 Bidirectional Association Both parties are aware of each other and can invoke each other’s public members.
1.4.2 Self‑Association A class may reference itself, which is useful in recursive structures.
1.5 Aggregation Aggregation is a special form of association representing a whole‑part relationship where parts can exist independently of the whole (has‑a). It is shown with a hollow diamond at the whole side.
1.6 Composition Composition is a stronger whole‑part relationship where parts cannot exist without the whole (strong aggregation). It is depicted with a filled diamond at the whole side.
Comprehensive Example The final diagram summarizes the relative strength of the relationships: Generalization = Realization > Composition > Aggregation > Association > Dependency.
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

software designUMLInheritanceaggregationcompositionAssociation
ITFLY8 Architecture Home
Written by

ITFLY8 Architecture Home

ITFLY8 Architecture Home - focused on architecture knowledge sharing and exchange, covering project management and product design. Includes large-scale distributed website architecture (high performance, high availability, caching, message queues...), design patterns, architecture patterns, big data, project management (SCRUM, PMP, Prince2), product design, and more.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.