aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Difference between Association & Aggregation & Composition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Difference between Association & Aggregation & Composition" Watch "Difference between Association & Aggregation & Composition" New topic
Author

Difference between Association & Aggregation & Composition

Jyotisree Dhar
Ranch Hand

Joined: Sep 15, 2001
Posts: 30
Hi All,
Please tell me the basic difference between association and aggregation and composition and how we can implement it in java program.

Regard's
Jyotisree Dhar
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Search the forum for many discussions on this. We haven't come to real clean conclusions, which leads me to believe there are other aspects of the design we care about more than the names of the relationships.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
To summarize my current understanding:

There are myriads of ways to implement them, but none of the implementations significantly differentiates between the kinds of relationships. It's easy to argue about their meaning endlessly, but near to impossible to agree on practical implications.

There is also an entry on this topic somewhere at http://faq.javaranch.com - a search on Aggregation should give you a signpost.


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
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
A few years ago we occasionally went to great pain to be precise about filled in circles or open circles (I think they're diamonds now) to indicate when one object controlled the lifespan of another. Say we had a holding, a party, and a relationship like "party owns holding". When you destroy the holding object, does that destroy the party object? (Depends entirely on the business rules by the way, so there is no "right" answer for this ad-hoc example.) I'm not sure whether that was UML's intended use for the notation or if we hijacked it, but I haven't gone to that much trouble in a model for years. I seem to be much more interested in dependencies.
[ May 04, 2005: Message edited by: Stan James ]
bparanj
Greenhorn

Joined: May 27, 2002
Posts: 27
This is a very good question. The difference is that in Composition you
will have additional code that involves deleting all the objects that
are part of the composite object.



class TreeCutter {



public void cut(Tree aTree) {

//Implementation that will destroy the tree

// object, Leaf object, TreeRoot object etc.

// This implementation depends on the programming language.

// Could be a separate destructor or garbage collector based

// implementation.

}



}



In aggregation the lifetime of the parts can be beyond its whole. So,
the destroy message will not propage to its components. If a plane is
destroyed, you could still use some of the re-usable parts in another
plane.



There is a lot confusion among the OOAD community on these concepts.
The UML 2.0 has cleared some of these confusion by defining them
clearly. For beginners I would suggest not to get hung up on the subtle
differences but to know when to use which form of association in your
model. Keep your model simple. If it does not add any clarity, don't
use aggregation.



Cheers,

Bala



For more articles on OOAD - http://www.zepho.com/articles.html




OOAD skills for the real world - http://uml.zepho.com



Moderator : <a href="http://groups.yahoo.com/group/OOAD_UML/" target="_blank" rel="nofollow">http://groups.yahoo.com/group/OOAD_UML/</a> <br />Home : <a href="http://www.zepho.com" target="_blank" rel="nofollow">http://www.zepho.com</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between Association & Aggregation & Composition