Understanding aggregation and composition
The object-oriented concept of aggregation arises in many OO designs. It comes up as frequently as inheritance does to specify object relationships. Aggregation is used to specify Has-A, whole-part, and in some cases, containment relationships. A class may contain aggregates of other objects. Aggregation can be broken into two categories – composition as well as a less strict and generalized form of aggregation.
Both generalized aggregation and composition imply a Has-A or whole-part relationship. However, the two differ in the existence requirements between the two related objects. With generalized aggregation, the objects can exist independently from one another, yet with composition, the objects cannot exist without one another.
Let’s take a look at each variety of aggregation, starting with composition.
Defining and implementing composition
Composition is the most specialized form of aggregation and is often what...