This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between Association & Aggregation & Composition

 
Jyotisree Dhar
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic