• Post Reply Bookmark Topic Watch Topic
  • New Topic

Aggregation and Composition  RSS feed

 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aggregation has a weaker relationship. (What does this mean? Also any example in Java where we use Aggregation)

Composition has a stronger realtionship. (What does this mean ? Also any example in Java where we use this concept like database connectivity etc ??)

I tried going through some of these topics but not successful.

 
Ravishanker kumar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aggregation:
Aggregation is an association where associated entity can exist without whole entity.
For example, suppose there is class User and Country.
Country: It contains information related to any country.
User: It contains attribute related to user and an object of Country as an instance member variable.

In this case if user is deleted then corresponding country should not be deleted (because country is a shared entity). This is an Aggregation (weaker) relationship.

Composition:
Composition is an association where associated entity can not exist without whole entity. If a whole is deleted then all parts are deleted. For example suppose there are two class User ad Address. User contains object of Address as an instance member variable, which represent address of a user. If user is deleted then its associated address will be also deleted (I am considering Address is not a shared entity and one address belongs to only one user). This is an example of a Composition (stronger) relationship

 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your response..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!