• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Aggregation

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can some one please confirm if me whether the following statement about Aggregation is true?
"When the Whole is created, the Parts are created and when the Whole is deleted, the Parts are also deleted".
My concern here is on the creation of the Whole.
Does its Parts need to be created as well?
Thanks.
Choon Meng
 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, that statement you supplied is describing a 'composition', not an aggregation relationship. Composition is stronger form of aggregation. With composition, the parts can only belong to a sinlge whole, and the parts are expected to live and die with the whole.
An example of an aggregation is a car. If a car dies, its parts can still be salvaged and used in another car. They are not subject to die with the rest of the car.
An example of a composition is you! If you die, the rest of your body parts will meet the same fate! Your arm cant live without you, but, you *can* live without your arm! HAHAHA
SAF
 
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Meng,
"When the Whole is created, the Parts are created and when the Whole is deleted, the Parts are also deleted".
This actually means a stronger association also called Composition.Composition can be obtained when the Whole manages the life-cycle of the Part.This means Aggregation of the Part in the Whole.In the code terms, you would have an attribute for Part in the Whole class.
The example I can think about now is about the Order(Whole) and the OrderLineItem(Part).It doesnot make sense for OrderLineItem to exist seperately or independently from the Order.It has to be strongly associated with the Order.If the Order is deleted, all the lineItems associated with it are also deleted.
The code may look something like this :
<pre>
public class Order {
/*
* Signifies aggregation!
*/
private OrderLineItem oli;
/*
* Every instance of Order holds a Value Object of
* OrderLineItem.You cannot change the reference once assigned!
*/
public Order() {
oli = new OrderLineItem();
}
/*
* An Order may remove a OrderLineItem, whenever it wants; i.e. life-cycle is managed by Order!
*/
public void remove(OrderLineItem oli) {
}
}
</pre>

Hope this helps,
Sandeep
[This message has been edited by Desai Sandeep (edited July 17, 2001).]
 
Meng Tan
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys.
I now have a better understanding of aggregation and composition!
 
Straws are for suckers. Now suck on this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic