Monday, 9 July 2012

Association , Aggregation and Composition in OOPS



Association :
                 Association is the relationships between classes. They can be one-to-one , one-to-many , many-to-many. Aggregation is a special case of Association.

               For example : An object of a class Person can be related with only one  object of person as a spouse. This is a one to one relation.
                                      An object of class Person can be related to any number of Car object as a owner. This is a one-to-many relation.

Aggregation :
                 It is regarded as 'has a' relation between two objects. But it is less constrained in a way that one object can exist even if the other one perishes.
              For example : A Desktop has a NIC(Network Interface Card). It means that they are related yet the desktop can exist without a NIC.

Composition:
               It is a form of Aggregation , but it has more constraint applied over it. Here the object in the relationship will exist only if the other exists.
               For example : A Desktop has a Mother Board. The desktop will exist only if the Mother Board Exists. Thus is a strong form of Aggregation .

No comments:

Post a Comment