Association vs Aggregation vs Composition

relationship between different objects

When a classes interacts with another class, a relationship develops between those two. This is called association. In an university, a student can learn from an instructor. We can model this relationship as follows.

The relationship can also show how many objects interact. This is called multiplicity. A student can learn from one or more instructors.

The relationship can also be bidirectional. An instructor can teach 1 or more students.

Association has two specific cases. Sometimes the relationship is modeled as a parent-child relationship(has-a relationship).

When a class can exist as part of another class, e.g. a hand is a part of person or an engine is a part of a car. The lifetime depends on the relationship. If the child can exist without the parent, we call it aggregation. If the child’s existence is dependent on the parent, we can it composition.

aggregation
composition

C++11/14, Qt, Juce

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store