IT SOLUTIONS
Office 916-726-5675
Tech Search:  Adv  More...
-Collapse +Expand
Search Coding Group:

Advanced
-Collapse +Expand
-Collapse +Expand
-Collapse +Expand
-Collapse +Expand
PRESTWOODSTORE
-Collapse +Expand
Prestwood Community
-Collapse +Expand
-Collapse +Expand
Sign in to see list of community groups here.
Prestwood eMagazine
Subscribe to our popular FREE monthly eMagazine.

Enter your email:

  From the November 2009 Issue of Prestwood eMag
 
Object Orientation (OO): OO/UML: Aggregation versus Composition
By Mike Prestwood
10/24/2002, Last updated 8/6/2009
 
Take Away:

Explains the "is a", "has a", "uses a", and "looks like" relationships (updated May 2007). "Is a" is inheritance, "looks like" is interfaces, "has a" is aggregation, and "uses a" is composition.

Coding KB Article:


I've been getting a lot of questions about the distinction between aggregation and composition lately. Both deal with part-of relationships and are extremely important concepts to understand.

Let's start with a defition of aggregation from the UML 1.4 glossary:

  • Aggregation - A special form of an association that specifies a whole-part relationship between the aggregate (whole) and a component part.

Types and Characteristics
There are various types and characteristics of aggregation relationsips (whole-part relationships) that describe the relationship between the whole and part in more detail. Lets continue with a few more definitions related to aggregation sub-types and characteristics (the Composition definition is from the UML 1.4 glossary):

  • Composition / Composition Aggregation - A form of aggregation which requires that a part instance be included in at most one composite at a time, and that the composite object is responsible for the creation and destruction of the parts.
  • Shareable Aggregation - A form of aggregation in which the part can exist on it's own and is therefore shareable among multiple owner classes.

More On Aggregations ("has a" relationship)
In an aggregation relationship, the part may be independent of the whole but the whole requires the part. An aggregation relationship is indicated in the UML with an unfilled diamond and a line as follows:

An Aggregation is an Association which denotes an "is part of" relationship. Unfortunately, the definition of this relationship is quite lax, so basically everyone is using his own interpretation. The only definitive (?) property is that in an instance graph, aggregations are not allowed to be circular - that is, an object can not be "a part of itself".

Composition (a strong type of "uses a" relationship)
A composition relationship, also known as a composite aggregation, is a stronger form of aggregation where the part is created and destroyed with the whole. A composition relationship is indicated...

Time To Sign In

You must sign in to read the rest of this document.

Not a member? Join now! Membership is instant and free!

Username:
Password:
 
Remember Me
Or...
 Create Free Account  Forgot Password?

More Info about "OO/UML: Aggregation versus Composition"

Article:  An Introduction to Object Orientation
Definition:  Composition
Link:  DotNetCoders.com UML Home Page
Definition:  Interface
Article:  Introduction to OO for the Paradox Community
Article:  Introduction to the Unified Modeling Language
Definition:  Polymorphism
KB Post:  PSDP Phases compared to UML Workflows
KB Post:  PSDP: Step 2 Planning Overview (Gen & Design Phases)
Article Contributed By Prestwood staff member Mike Prestwood:
mprestwood
Email Approved! E
Mike Prestwood is author of 9 books and many articles and is President of Prestwood Software. If you have a project you wish to discuss with Mike, you can email him at the address at the bottom of this page or call him at 916-726-5675 x205.

Comments about "OO/UML: Aggregation versus Composition"

Oldest To Newest

Add Comment
First Comment
Reader...
inghamc -Collapse +Expand

Chris Ingham
Visits: 2
MB Posts: 0

KB Articles: 0
Rank: Cadet 3rd Year

Joined: Apr 2005
Location: CO USA
Comment 1 of 6
Monday, April 25, 2005

I don't understand the composition example - how is an engine responsible for the creation of gas?

Reader...
robert bosch
call_krmohan -Collapse +Expand

rama mohan
Visits: 2
MB Posts: 0

KB Articles: 0
Rank: Cadet 1st Year

Joined: Oct 2007
Location: bangalore IN
Comment 2 of 6
Wednesday, October 31, 2007

fine

Reader...
mohitsi -Collapse +Expand
 (Inactive)
Mohit Singhal
Visits: 1
MB Posts: 0

KB Articles: 0
Rank: Cadet 1st Year

Joined: Feb 2008
Location: USA
Comment 3 of 6
Tuesday, February 05, 2008

Hi Mike,

 Just would like add some comment on the examples given above:

-         In aggregation relationship, the ‘part’ object reference can be re-used & creation of ‘part’ object is not the responsibility of the ‘whole‘object usully. It would have been created somewhere else, and passed to the ‘whole’ object as a method argument.

-         In composition, the life cycle of the ‘part’ is controlled by the ‘whole’.

So, if I am right then your pseudo code examples would need to get swapped within each other.

ie. SparkPlug/Car example shows composition & Room/building example shows aggregation.

Waiting for your response....

Thanks in advance,

Mohit


Reader...
vletter1-1 -Collapse +Expand

a l
Visits: 2
MB Posts: 0

KB Articles: 0
Rank: Cadet 2nd Year

Joined: Apr 2009
Comment 4 of 6
Saturday, April 25, 2009

Hi Mike,

with the pseudo code you provided from aggregate and composition, I totally understand what it means.

Can you also provide the pseudo code from inheritance and interface?

thanks

Andrew


Reader...
Cognizant
soniya_ahuja -Collapse +Expand

Soniya Ahuja
Visits: 1
MB Posts: 0

KB Articles: 0
Rank: Cadet 1st Year

Joined: Aug 2009
Location: Raigad, UNK IN
Comment 5 of 6
Thursday, August 06, 2009

The article is indeed impressive. I tried reading on this topic at a few other places, but none were as comprehensible as this. A concise but effective way of explaining aggregation and its types.


Latest Comment
Author...
Prestwood I.T. Solutions
PS Staff
Moderator
Mike Prestwood -Collapse +Expand

Mike Prestwood
Visits: 7657
MB Posts: 1273

KB Articles: 1879
Rank: Fleet Admiral

Joined: Oct 2000
Location: Citrus Heights, CA USA
Comment 6 of 6
Thursday, August 06, 2009

Thanks Soniya. It's always nice to get positive feedback.

Would you like to comment? Reply? Ask a question? Say thanks?
+Add Comment

 KB Article #100035 Counter
49589
Since 4/2/2008
Brought to you by Prestwood I.T. Solutions We hope you are enjoying our knowledge base! We welcome your participation in our open online community. As the caretakers, we pay our staff to moderate, edit, and contribute free content here in an effort to promote our software development company. Keep us in mind if you or your company needs help. Whether you need a single developer or a team, consider Prestwood. We are an American company that keeps jobs in America (no off shoring and no need for H-1B developers). Our hope is that you will put some or all of your development tasks in our hands. We specialize in hourly help (1 hour minimum), custom websites from $2k to $40k, business database applications from $5k to $60k, and enterprise application development starting from $20k. Talented Developer?
If you are a talented developer and would like to work with us, start by filling out our Register for Work form.
 
 10,482 registered community members.   Members Online Now
Mike Prestwood
If you have any questions,
please Contact Us.
--Mike Prestwood
Copyright 1995-2010 Prestwood I.T. Solutions.
Made in the U.S.A.
No H1-B. No offshoring.
A CA corporation.
CA CMAS certified.
Certified CA small business.
www.prestwood.com is part of the Prestwood Family of Websites.
Development by Mike Prestwood (ASP, ASP.Net, and Delphi to MS-SQL 2008).
Knowledgebase powered by ASPSuite KB module (programming by Mike Prestwood).
All rights reserved.

[Security & Privacy]
 

Attention Developers!
Join the Prestwood Computer Community (PPC)

OO, UML, DotNet, ASP.Net, C++, Java, PHP, ASP, JavaScript, Delphi, Access / Paradox
blogs
message boards
knowledge base
articles
jobs database
resume database
get published!
Visit Community | Sign Up Now!
It's free and takes less than 30 seconds.