aggregation or composition?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

aggregation or composition?

Post 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.
Last edited by raghavan20 on Mon Dec 18, 2006 8:21 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'm not sure what you're asking.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.)
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post 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.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

good one maugrim
User avatar
zyklone
Forum Commoner
Posts: 29
Joined: Tue Nov 28, 2006 10:25 pm

Post 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!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Gravity cars don't have engines. Image
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

feyd wrote:Gravity cars don't have engines. Image
Then gravity cars aren't cars. ImageImage
(#10850)
Post Reply