Composition and Aggregation
In this tutorial, we are going to discuss composition and aggregation in java.
In the case of composition, whenever a container object is destroyed, all contained objects will be destroyed automatically. i.e., without an existing container object, there is no chance of an existing contained object, i.e., container and contained objects having a strong association.
University is composed of several departments. Whenever you are closing university automatically, all departments will be closed. The relationship between university object and department object is the strong association which is nothing but composition.
Whenever a container object is destroyed, there is no guaranty of the destruction of contained objects, i.e., without an existing container object, there may be a chance of an existing contained object. i.e., container objects just maintain references of contained objects. This relationship is called weak association, which is nothing but Aggregation.
Several professors will work in the department. Whenever we are closing the department still there may be a chance of existing professors. The relationship between department and professor is called weak association, which is nothing but Aggregation.