• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Aggregation vs Composition

 
Vishal Gupta
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • 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!!!
 
Maniganda Prakashh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please refer
http://faq.javaranch.com/java/AssociationVsAggregationVsComposition
[ June 25, 2008: Message edited by: Maniganda Prakash ]
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks Guys
 
Swapnil Sonawane
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vishal, Please modify your name according to Javaranch naming policy.
[ June 28, 2008: Message edited by: Swapnil Sonawane ]
 
Stephen Davies
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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!
 
arulk pillai
Author
Ranch Hand
Posts: 3387
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic