Fundamentals 13 min read

UML Relationship Cheat Sheet: From Dependency to Realization

This article explains the six core UML relationship types—Dependency, Association, Aggregation, Composition, Generalization, and Realization—detailing their semantics, visual notations, code representations in Java/C++, and practical distinctions such as lifecycle ownership and usage contexts.

Programmer DD
Programmer DD
Programmer DD
UML Relationship Cheat Sheet: From Dependency to Realization

UML describes object and class relationships using six main types: Dependency, Association, Aggregation, Composition, Generalization, and Realization.

Dependency (Dependency): Element A changes affect element B, but not vice‑versa; represented by a dashed arrow pointing to the depended‑on element.

Generalization (Generalization): The classic inheritance relationship ("is‑a"); shown with a solid line and a hollow triangle arrow pointing to the general element.

Realization (Realization): An element defines a contract that another element implements; depicted with a hollow triangle and a dashed line.

Association (Association): A structured, weaker link where associated elements can be considered independently; drawn with a solid line.

Aggregation (Aggregation): A special form of association indicating a whole‑part relationship; shown with a solid line ending in a hollow diamond.

Composition (Composition): A stronger variant of aggregation where the part's lifecycle is bound to the whole; depicted with a solid line ending in a filled diamond.

Dependency (Dependency)

Dependency is a one‑way relationship; avoid bidirectional dependencies.

In Java or C++, it appears as local variables, method parameters, or static method calls.

public class Person {
    void buy(Car car) {
        ...
    }
}

In diagrams, dependency is shown with a dashed arrow. It represents a usage relationship without ownership.

Association (Association)

Association links classes so that one class knows another's attributes and methods.

It can be unidirectional or bidirectional; in Java/C++ it is implemented via member variables.

public class 徒弟 {
}

public class 唐僧 {
    protected: list<徒弟> tdlist;
}

Diagrammatically, association uses a solid line; an arrow may indicate direction.

Aggregation (Aggregation)

Aggregation is a stronger form of association, representing a whole‑part relationship.

The part can exist independently of the whole and may be shared.

Implemented via member variables, but the classes reside at different hierarchy levels.

public class 引擎 {
}

public class 轮胎 {
}

public class 汽车 {
    protected: 引擎 engine;
    protected: 轮胎 tyre[4];
}

Shown with a solid line ending in a hollow diamond.

Composition (Composition)

Composition is a stronger variant of aggregation; the part's lifecycle is tied to the whole.

If the whole is destroyed, its parts are destroyed as well.

class 肢 {
}

class 人 {
    protected: 肢 limb[4];
}

Represented by a solid line ending in a filled diamond.

Generalization (Generalization)

Generalization models inheritance; in Java it is expressed with the extends keyword and in UML with a solid line and a hollow triangle arrow.

Realization (Realization)

Realization models the implementation of an interface; in Java it uses the implements keyword and in UML a dashed line with a hollow triangle arrow.

Differences Between Relationship Types

Aggregation vs. Composition

Both express whole‑part, but aggregation does not own the part's lifecycle, while composition does.

Multiple wholes can share the same part in aggregation; they cannot in composition.

Aggregation is a "has‑a" relationship; composition is a "contains‑a" relationship.

Association vs. Aggregation

Association is a neutral structural link; aggregation adds a whole‑part semantic.

In code, both use member variables, but their logical meaning differs.

Association vs. Dependency

Association denotes a stronger, often long‑term structural link.

Dependency is a weaker, temporary usage relationship where changes in the provider affect the client.

Generalization vs. Realization

Generalization models class‑to‑class or interface‑to‑interface inheritance.

Realization models a class implementing an interface.

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 designUMLObject-Orienteddependencyaggregationcompositionrelationship
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

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.