Aggregation and Composition (Has-a relationship)

Posted on

Aggregation and Composition (Has-a relationship)

 Has-a relationship : 

  • Has- a relationship is also called composition and aggregation.
  • The principle benefit of Has-a relationship is re-usability of the code.
  • There is no such thing as a particular key phrase to implement Has-a relationship however more often than not we’re relying upon new key phrase.

 

Composition :

With out current container object if there isn’t any probability of current the contained objects then container and contained objects are strongly related and this affiliation is known as composition.

Example : College containing numerous departments with out current college there isn’t any probabilities of current departments therefore college and departments are strongly related to one another and this sturdy affiliation is known as composition.

 

Aggregation :

with out current the container object if there’s a probability of current the contained objects then container and the contained objects are weakly related to one another and this weak affiliation is known as aggregation.

Example : Division consists of a number of professors. With out current division there will be the probabilities of current professor objects. Therefore division and professors objects are weakly related and that is weak affiliation.