File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes association, aggregation, Composition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "association, aggregation, Composition" Watch "association, aggregation, Composition" New topic
Author

association, aggregation, Composition

sita raman
Ranch Hand

Joined: Jul 10, 2005
Posts: 33
Can any one define and differentiate between association, aggregation, Composition with an example ?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41621
    
  55
Not an example, but this page may help: AssociationVsAggregationVsComposition


Ping & DNS - my free Android networking tools app
sita raman
Ranch Hand

Joined: Jul 10, 2005
Posts: 33
thanks.But i had alrsdy gone through this link.still am not clear about the concept.please advice
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41621
    
  55
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

Joined: Jul 11, 2001
Posts: 14112
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.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
sita raman
Ranch Hand

Joined: Jul 10, 2005
Posts: 33
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

Joined: Jul 11, 2001
Posts: 14112
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*.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: association, aggregation, Composition