Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
AggregationAndComposition uml 17 May 2003
Few things in the UML cause more consternation than aggregation and composition, in particular how they vary from regular association.
The full story is muddied by history. In the pre-UML methods there was a common notion of defining some form of part-whole relationships. The trouble was that each method defined different semantics for these relationships (although to be fair, some of these were pretty semantics free).
So when the time came to standardize, lots of people wanted part-whole relationships, but they couldn't agree on what they meant. So the UML definers introduced two relationships.
aggregation (white diamond) has no semantics beyond that of a regular association. It is, as Jim Rumbaugh puts it, a modeling placebo. People can, and do, use it - but there are no standard meanings for it. So if you see it, you should inquire as to what the author means by it. I would advise not using it yourself without some form of explanation.
composition (black diamond) does carry semantics. The most particular is that an object can only be the part of one composition relationship. So even if both windows and panels can hold menu-bars, any instance of menu-bar must be only held by one whole. This isn't a constraint that you can easily express with the regular multiplicity markers.
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
Originally posted by aakash bhatt:
What is the difference between Asscoiation, Composition and Aggregration.
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
Originally posted by Lasse Koskela:
Here are a couple of quick examples. Guys, correct me if I forgot to think while typing
Association(s):
Composition:
Aggregation:
Originally posted by Comert Sagiroglu:
In Lasse Koskela's example, I think aggregation and composition code are misplaced.
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
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
Co-Author of <a href="http://www.oreilly.com/catalog/jswing2" target="_blank" rel="nofollow">Java Swing</a><br />Co-Creator of <a href="http://www.sun.com/training/catalog/courses/CX-310-055.xml" target="_blank" rel="nofollow">SCJP 5.0</a> and <a href="http://www.sun.com/training/certification/java/associate_beta.xml" target="_blank" rel="nofollow">SCJA</a> exams
Help gets you when you need it!
Originally posted by Maki Jav:But what is "clearly" an association then?
<i>The lyf so short, the craft so long to lerne.</i> --Geoffrey Chaucer (c. 1343-1400)
Stefan Wagner wrote:
Originally posted by aakash bhatt:
What is the difference between Asscoiation, Composition and Aggregration.
As example:
A person needs to have a heart, a liver, a head.
This you would model as composition.
A person may have a car, a house, a sun-workstation.
This would be an aggregation.
In programming, the situation is normally not that clear (and in real live, you always find examples, which contradict your theory - people with two heads, synthetic heart and no liver at all .
If my classes, when X has an Y, then mostly because it needs to have it.
I guess you use association, if the attribut has it's own livecycle, and is only referenced by the class (the class may change this association and exist without this attribut).
be a well encapsulated person, don't expose your privates, unless you public void getWife()!
Consider Paul's rocket mass heater. |