Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

association, aggregation, Composition

 
sita raman
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one define and differentiate between association, aggregation, Composition with an example ?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not an example, but this page may help: AssociationVsAggregationVsComposition
 
sita raman
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks.But i had alrsdy gone through this link.still am not clear about the concept.please advice
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you try to describe those concepts in your own words, and others can jump in and help if you feel you're on shaky ground.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you asking for a code exmaple here?

Then the problem is that there are many ways to implement them, and the code doesn't even necessarily look differently. The difference between the three concepts is much more in the intention than in the structure of the code.
 
sita raman
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please advice whether my concept is correct.

Association is similar to the HAS relationaship.ie one class have the reference of the other.

Class A{
B b;
}

Aggregation is the collection of reference.

Class A{
Vector v1;//contains the collection of reference A.
}

Composition is one which cretes and detroy the othe rererence.

Class A{
B a=new B();
}
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, every single of those examples could be either Composition, Aggregation or simple Association. (Although the probability for the last to be Composition might be a bit higher.)

It really depends on what the code that you haven't shown does with the object, and *why*.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic