This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
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
be a well encapsulated person, don't expose your privates, unless you public void getWife()!
Joined: Apr 01, 2008
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"
Joined: Jul 23, 2008
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"
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!