Fundamentals 11 min read

UML: Dependency, Association, Aggregation, Composition, Generalization, Realization

This article explains the six fundamental UML relationship types—Dependency, Association, Aggregation, Composition, Generalization, and Realization—detailing their semantics, visual notations, code examples in Java/C++, and the distinctions among them, helping developers model object interactions accurately.

Programmer DD
Programmer DD
Programmer DD
UML: Dependency, Association, Aggregation, Composition, Generalization, Realization

UML describes various ways objects and classes can relate, including Dependency, Association, Aggregation, Composition, Generalization, and Realization.

Dependency

Dependency means element A changes affect element B, but not vice‑versa; B depends on A. It is shown with a dashed arrow pointing to the depended‑on element.

Characteristics: one‑way, often appears as local variables, method parameters, or static method calls in Java/C++.

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

Association

Association is a structural, usually bidirectional, relationship where one class knows another class's attributes and methods. In code it is implemented via member variables.

public class Disciple {
    // ...
}

public class TangSeng {
    protected: list<Disciple> tdlist;
}
Association relationship diagram
Association relationship diagram

Aggregation

Aggregation is a special form of association that represents a whole‑part relationship (has‑a). The part can exist independently of the whole.

public class Engine {
    // ...
}
public class Tire {
    // ...
}
public class Car {
    protected: Engine engine;
    protected: Tire tyre[4];
}
Aggregation relationship diagram
Aggregation relationship diagram

Composition

Composition is a stronger form of aggregation where the part’s lifecycle is bound to the whole; when the whole is destroyed, its parts are destroyed as well.

class Limb {
    // ...
}
class Person {
    protected: Limb limb[4];
}
Composition relationship diagram
Composition relationship diagram

Generalization

Generalization models inheritance (is‑a) relationships between a more general element and a more specific one. In Java it is expressed with the extends keyword.

Generalization diagram
Generalization diagram

Realization

Realization models the contract between an interface (the definition) and a class that implements it. In Java it is expressed with the implements keyword.

Realization diagram
Realization diagram

Differences Between Relationships

Aggregation vs. Composition : Both are whole‑part relationships, but in aggregation the part can exist independently of the whole, while in composition the part’s lifecycle is tied to the whole.

Association vs. Aggregation : Association is a generic structural link; aggregation adds the whole‑part semantic.

Association vs. Dependency : Association represents a stronger, often long‑term structural link, whereas dependency is a weak, temporary usage relationship.

Generalization vs. Realization : Generalization models inheritance between classes (or interfaces), while realization models a class fulfilling an interface contract.

Overall, the strength of these relationships can be ordered as: 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.

UMLObject-OrienteddependencyaggregationcompositionAssociation
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.