File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Associate Certification (SCJA,OCAJ 5/6) and the fly likes Aggregation vs Composition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Associate Certification (SCJA,OCAJ 5/6)
Bookmark "Aggregation vs Composition" Watch "Aggregation vs Composition" New topic
Author

Aggregation vs Composition

Vishal Gupta
Ranch Hand

Joined: Apr 01, 2008
Posts: 32
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!!!


Vishal Gupta<br />------------<br />SCJA
Maniganda Prakashh
Greenhorn

Joined: Oct 01, 2005
Posts: 9
Please refer
http://faq.javaranch.com/java/AssociationVsAggregationVsComposition
[ June 25, 2008: Message edited by: Maniganda Prakash ]
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Howdy Vishal R Gupta,

Welcome to JavaRanch

Hope the link provided by Maniganda Prakash would help you!


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Vishal Gupta
Ranch Hand

Joined: Apr 01, 2008
Posts: 32
Thanks Guys
Swapnil Sonawane
Ranch Hand

Joined: Jan 02, 2008
Posts: 190
Vishal, Please modify your name according to Javaranch naming policy.
[ June 28, 2008: Message edited by: Swapnil Sonawane ]

Swapnil S. Sonawane<br /> <br />B.Tech (Expected May 2009)<br />Computer Science, NIT Durgapur, India<br />SCJA 1.0
Stephen Davies
Ranch Hand

Joined: Jul 23, 2008
Posts: 352
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


be a well encapsulated person, don't expose your privates, unless you public void getWife()!
Vishal Gupta
Ranch Hand

Joined: Apr 01, 2008
Posts: 32
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

Joined: Jul 23, 2008
Posts: 352
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

Joined: May 31, 2007
Posts: 3219
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.


Java Interview Questions and Answers Blog | Amazon.com profile | Java Interview Books
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Aggregation vs Composition