Monday, July 12, 2010

JAVA Composition vs Aggregation

Association - it's a structural relationship between two classifiers i.e. classes or Use cases.
An Association specifies how objects are related to one another.
Aggegation & Composition are associations with following  qualities.

Aggegation is normally understood as a "has-a" relationship.
Here both the entities continue to have their own independent existence.
Aggregations are not allowed to be circular - that is, an object can not be "a part of itself".

Composition is normally understood as a "contains-a" relations.
It depicts a Whole-part relationship and the 'part' entity doesn't have its own independent existence.
Adds a lifetime responsibility to Aggregation.

  • In case of Aggregation, both the entities will continue to have their independent existence whereas in case of Composition the lifetime of the entity representing 'part' of the "whole-part" is governed by the entity representing 'whole'.

  • Aggregation represents a loose form of relationship as compared to that represented by Composition which depicts a stronger relationship.

  • Example:
    An Employ can have Cabin(seating arrangement) and Food preferences.
    Cabin can exist without employ ie Aggegation
    Food Preferences of employ  cannot exist without employ as they are specific to that employ object -- Composition

    Sources

    Composition vs Aggregation. How is Association related to them?

    Association Vs Aggregation Vs Composition   


    Lables: JAVA FAQ,Aggregation,Composition,
    Association