IT SOLUTIONS
Your TECHNOLOGY partner! 
-Collapse +Expand
Coder
Search Coder Group:

Advanced
-Collapse +Expand Coder Group Home
-Collapse +Expand Message Board
-Collapse +Expand Coder KB
-Collapse +Expand Coder Study Test
PRESTWOODCERTIFIED
-Collapse +Expand Coder Store
PRESTWOODSTORE
-Collapse +Expand Members Only

Prestwood eMagazine

May Edition
Subscribe now! It's Free!
Enter your email:

   ► KBRole-Based T...Coding & OOObject Orien...    
Go To Random Article
  From the January 2013 Issue of Prestwood eMag
 
Coder Object Orientation (OO):
OO/UML: Aggregation versus Composition
 
Posted 11 years ago on 10/24/2002 and updated 5/21/2010
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.



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!

UserID or Email:  Enter your account email, permanent UserID, or current display name.
Password: 
 
  Remember Me
Or...
 Create a Profile  Forgot Password?

More Info

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)

Comments

1 Comments.
Share a thought or comment...
First Comment

inghamc
Comment 1 of 8
I don't understand the composition example - how is an engine responsible for the creation of gas?
Posted 8 years ago


call_krmohan
Comment 2 of 8
fine
Posted 6 years ago


mohitsi
Comment 3 of 8

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

Posted 5 years ago


vletter1-1
Comment 4 of 8

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

Posted 49 months ago


soniya_ahuja
Comment 5 of 8

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.

Posted 45 months ago


Mike Prestwood
Comment 6 of 8

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

Posted 45 months ago


Anonymous
Comment 7 of 8

Good, usable article, thaks.

---
Spender
Posted 24 months ago

Latest Comment

Anonymous
Comment 8 of 8

i want  a artical to transforoming aggeraction campastion social awerness project

---
akram
Posted 20 months ago
 
Write a Comment...
Full Editor
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post:

Enter your name and security key.

Your Name:
Today's security key = P187A
Enter key:
Article Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.


 KB Article #100035 Counter
76392
Since 4/2/2008
-
  Load Time=less than 1 second.
 
Print This

KB Post Options:
-
 
Have a question? Need our services? Contact us now.
--Mike Prestwood

Call: 916-726-5675

email: info@prestwood.com


-
 
Connect With Us...
PrestwoodBoards
Join Us!
Facebook
Like our page!
Twitter
Follow us!
LinkedIn
Join Group
YouTube
View channel.
Go ahead!   Use Us! Call: 916-726-5675 


©1995-2013 Prestwood IT Solutions.   [Security & Privacy]   Made in the U.S.A..   No H1-B.   No offshoring.