About

Associations, Aggregation, and Composition

Associations, Aggregation, and Composition

Object-oriented systems model interactions through well-defined relationships between classes.

1. Association

Objects are connected and interact, but neither class owns the lifecycle of the other.

2. Aggregation (Weak Whole-Part)

A “has-a” whole-part relationship where the part can exist independently of the whole.

3. Composition (Strong Whole-Part)

A whole-part relationship where the part’s lifecycle is bound strictly to the whole.

4. Dependency (Uses-A)

A temporary relationship where one class uses another (e.g. as a parameter in a method).

Exercise 1

How do you distinguish aggregation from composition in terms of lifecycle?

Show solution ↓
Solution

In aggregation, parts exist independently of the whole (weak ownership). In composition, the lifetime of the part is managed directly by the whole (strong ownership), so destroying the whole destroys the parts.