UML Relationship Types: Dependency, Association, Aggregation, Composition, Generalization, and Realization
This article explains UML's six core relationship types—Dependency, Association, Aggregation, Composition, Generalization, and Realization—detailing their semantics, visual notations, and how they are expressed in Java or C++ code.
UML defines several ways to describe relationships between objects and classes, including Dependency, Association, Aggregation, Composition, Generalization, and Realization.
Dependency is a one‑way relationship where a change in element A may affect element B; it is shown with a dashed arrow. Types of dependency such as usage, call, parameter, send, instantiate, trace, refine, derive, access, import, friend, and bind are described with UML stereotypes.
Method‑parameter example of a dependency:
public class Person {
void buy(Car car) {
// ...
}
}Association represents a structural link between classes, typically implemented via member variables; it can be uni‑ or bi‑directional and is shown with a solid line.
Association example in Java/C++:
public class 徒弟 {
// ...
}
public class 唐僧 {
protected: list<徒弟> tdlist;
}Aggregation is a special form of association indicating a whole‑part relationship, depicted with a hollow diamond on the whole side.
Aggregation example:
public class 引擎 {
// ...
}
public class 轮胎 {
// ...
}
public class 汽车 {
protected: 引擎 engine;
protected: 轮胎 tyre[4];
}Composition is a stronger whole‑part relationship where the part’s lifecycle is bound to the whole, shown with a filled diamond.
Composition example:
class 肢 {
// ...
}
class 人 {
protected: 肢 limb[4];
}Generalization models inheritance (a “is‑a” relationship) and is drawn with a solid line and a hollow triangle arrow pointing to the general element.
Realization models the implementation of an interface, using a dashed line with a hollow triangle arrow.
These UML relationships help designers capture semantic connections between software elements, while the code snippets illustrate how they manifest in typical Java or C++ implementations.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.