Page 1 of 1

aggregation or composition?

Posted: Mon Dec 18, 2006 5:45 am
by raghavan20
eventhough i know aggregation is where elements involved can still exist in real world alone and composition is where elements involved cannot exist in real world alone, i could not still figure out in certain cases.

Example scenarios:
1. an user has orders
2. an user has credit cards
3. an order has orderlines
4. an order has its own order history
5. an orderline that has its own shipment tracking object

Please let me know whether you think each one of them as aggregation or composition; i would be glad if you can explain your decisions. Thanks.

Posted: Mon Dec 18, 2006 8:14 am
by feyd
I'm not sure what you're asking.

Posted: Mon Dec 18, 2006 8:16 am
by raghavan20
feyd wrote:I'm not sure what you're asking.
i have just presented a few examples to see whether you guys mark them as composition or aggregation as this would help me to understand the concept better.

Posted: Mon Dec 18, 2006 8:45 am
by feyd
What's an "orderline"? Should I assume it's a Line Item?
  1. Aggregate. Orders are not components of Users.
  2. Aggregate. Credit Cards are typically not components of Users.
  3. Composition. Line items are components of Orders.
  4. Aggregate. Order history is generally not a component of an Order.
  5. Neither. Orders are broken into shipments. These shipments may contain one or more line items, even partial line items (variable quantities.)

Posted: Wed Dec 20, 2006 4:34 am
by raghavan20
if a car has steering, wheels, engine, etc., now does the car aggregate or compose these?
i have this doubt because steering, wheels & engine are still meaningful when they exist alone.

Posted: Wed Dec 20, 2006 6:24 am
by Maugrim_The_Reaper
A car aggregates all those - i.e. each can exist by itself as a separate entity: Aggregation. If you consider something like an HTML document in contrast, you would compose tags into a singular HTML object. Since destroying the document, destroys all the tags held by that document, it's Composition.

The two can be pretty confusing ;). But you're more likely to find Aggregation for the system you're describing. Each component you've mentioned can exist outside it's parent object - whether as a standalone object, or a row in your database. Composition points to more of a situation where one object can only exist if another (a parent or collector object) exists to hold it.

Posted: Wed Dec 20, 2006 6:26 am
by raghavan20
good one maugrim

Posted: Sun Dec 31, 2006 8:23 am
by zyklone
i think its composite. coz the car compose of engine, wheel, etc.

like TABLE it composes LEGS. you cant have table without legs. and you cant have a car without wheels, engine.. i hope this would help.. thanks!

Posted: Sun Dec 31, 2006 8:42 am
by feyd
Gravity cars don't have engines. Image

Posted: Sun Dec 31, 2006 1:07 pm
by Christopher
feyd wrote:Gravity cars don't have engines. Image
Then gravity cars aren't cars. ImageImage