This week's book giveaway is in the Cloud/Virtualizaton forum.We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!

# Aggregation

Meng Tan
Ranch Hand
Posts: 115
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

SAFROLE YUTANI
Ranch Hand
Posts: 257
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

Desai Sandeep
Ranch Hand
Posts: 1157
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
Thanks guys.
I now have a better understanding of aggregation and composition!