Composition Vs Aggregation

Composition Vs Aggregation
Composition

In the case of composition whenever container object is destroyed all contained objects will be destroyed automatically. i.e., without existing container object there is no chance of existing contained object i.e., container and contained objects having strong association.

E.g

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 strong association which is nothing but composition.

Aggregation

Whenever container object destroyed, there is no guaranty of destruction of contained objects i.e., without existing container object there may be a chance of existing contained object. i.e., container objects just maintains references of contained objects. This relationship is called weak association which is nothing but Aggregation.

E.g

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.

Composition Vs Aggregation


Scroll to top