File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Difference between Association & Aggregation & Composition" Watch "Difference between Association & Aggregation & Composition" New topic

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.

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

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 - 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 ]

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

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.



For more articles on OOAD -

OOAD skills for the real world -

Moderator : <a href="" target="_blank" rel="nofollow"></a> <br />Home : <a href="" target="_blank" rel="nofollow"></a>
I agree. Here's the link:
subject: Difference between Association & Aggregation & Composition
jQuery in Action, 3rd edition