Aggregation
In this lesson, you'll get familiar with a new way of linking different classes.
We'll cover the following
Aggregation is a specialized form of association. It follows the Has-A model. In aggregation, a class uses the objects of other classes. Here, we will refer to the class, using the objects of other classes, as the container class, and the classes whose objects are being used as the contained classes.
The container class contains the references to the objects of the contained classes.
Let’s see what makes aggregation unique.
Independent Lifetimes
In aggregation, the lifetime of the contained object does not depend on the lifetime of the container object.
The container object could get deleted but the contained object can continue to exist in the program. The container only contains a reference to the contained, which removes the latter’s dependence on the former.
Get hands-on with 1400+ tech skills courses.