• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Aggregation vs Composition

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the difference between Aggregation and Composition?
I think I understand Composition but having a doubt on Aggregation.
I wonder why 'Aggregation' is not included in SCJA exam objectives!!!
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please refer
http://faq.javaranch.com/java/AssociationVsAggregationVsComposition
[ June 25, 2008: Message edited by: Maniganda Prakash ]
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy Vishal R Gupta,

Welcome to JavaRanch

Hope the link provided by Maniganda Prakash would help you!
 
Vishal Gupta
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Guys
 
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vishal, Please modify your name according to Javaranch naming policy.
[ June 28, 2008: Message edited by: Swapnil Sonawane ]
 
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vishal,

As a student to Java myself (SCJA) I stumbled upon this issue in a Mock exam.For me the easiest way for htinking about association and aggregation is that association, think of "Has a" for example a customer "has an" address. Where as in aggregation its "made up of" so (from my experience) a PC, is made up of a mouse, a cpu, a monitor, a keyboard etc" (a pc is the aggregate of..) each of these can be a seperate object (class) which can exist independently of its aggregate (a mouse, or keyboard (class)can exist without the PC class) it is also asymmetrical meaning that a PC class can be the aggregate of a mouse and other classes, but a mouse and other classes in this case cannot be an aggregate of a PC Class. In UML association is a line with a multiplicity indicator (or open arrow if navigable) composition is a solid diamond, and aggregation - so I have learned is a hollow diamond. This is my interpretation, but check out the other links to be certain.Hope this helps

Steve
 
Vishal Gupta
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Stephen,
in short
Association == "has A"
aggregation == "made up of"
Composition == "made up of and having same lifetime" or "made up of and managing lifecycle of its part"

Thanks
 
Stephen Davies
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vishal Gupta:
Thanks Stephen,
in short
Association == "has A"
aggregation == "made up of"
Composition == "made up of and having same lifetime" or "made up of and managing lifecycle of its part"

Thanks



Thats it, however Sun uses the term "lifecycle" for composition. That is to say a composition relationship is basically an association of vital members, those, members lifecyles are directly effected by the possesing class, and cannot exist without it (but they also are not neccessarily aware of the parent class). For example a Book(class) "has pages" but it is also "composed of pages" those pages (page classes for example), do not know what book they are in, but destroy the book, and all the pages are also destroyed. Or a Body class may have many organ classes or types, but kill the body and all the organs die!
 
Author
Posts: 3473
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Composition is a stronger relationship. I generally use the order and line items example. When an order is deleted the line items need to be deleted or removed as well.
 
If you send is by car it's a shipment, but if by ship it's cargo. This tiny ad told me:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic