aggregation or composition?
Moderator: General Moderators
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
aggregation or composition?
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.
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.
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
What's an "orderline"? Should I assume it's a Line Item?
- Aggregate. Orders are not components of Users.
- Aggregate. Credit Cards are typically not components of Users.
- Composition. Line items are components of Orders.
- Aggregate. Order history is generally not a component of an Order.
- Neither. Orders are broken into shipments. These shipments may contain one or more line items, even partial line items (variable quantities.)
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
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.
The two can be pretty confusing
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
