File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes Aggregation 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 "Aggregation" Watch "Aggregation" New topic
Author

Aggregation

Meng Tan
Ranch Hand

Joined: Jan 20, 2001
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

Joined: Jul 06, 2001
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

Joined: Apr 02, 2001
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).]


<b>Sandeep</b> <br /> <br /><b>Sun Certified Programmer for Java 2 Platform</b><br /> <br /><b>Oracle Certified Solution Developer - JDeveloper</b><br /><b>-- Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java </b><br /><b>-- Object-Oriented Analysis and Design with UML</b><br /> <br /><b>Oracle Certified Enterprise Developer - Oracle Internet Platform</b><br /><b>-- Enterprise Connectivity with J2EE </b><br /><b>-- Enterprise Development on the Oracle Internet Platform </b>
Meng Tan
Ranch Hand

Joined: Jan 20, 2001
Posts: 115
Thanks guys.
I now have a better understanding of aggregation and composition!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Aggregation