Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

How do u know which is composition and which is aggregation

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone tell me how do we know it is a composition or aggregation?. or what is the difference between composition and aggregation in UML?.
COmposisition is represented with filled diamond.
aggregation is with empty diamond
given a situation how do to decide which is which?
thanks a lot for ur help
Ram Nath
 
Author
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Composition indicates a whole part relationship with strong ownership and "coincident lifetimes". An individual part cannot be "owned" by multiple wholes. For example, the relationship between a person and their lungs can be modeled as a composition relationship, since the person "owns" their lungs.
Aggregation indicates a whole part relationship without the strong ownership. The relationship between a person and their clothes might be better modeled as aggregation.
Hope it helps
CT
------------------
C.T. Arrington
Author of Enterprise Java with UML
 
Ram Nath
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arrington,
Thank you so much. One more question, so when we model the class the aggregation will be a pointer to other object and in case of composition the entire object is enclosed within the current class. Am i right?.
Thanks a lot for all your help
 
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ram Nath,
Talking from programming point of view (say wrt Java) :
Considering Department and Employee classes as examples:
In the Department class, you would usually have a method which returns MultiObjects of Employees.It could be something like this:

The above is an Aggregation example - A loose relationship is represented between Department and Employee -One or more Employees works in a Department.Since, they cannot be the intergral part of the department, hence it is best represented by aggregation.
Considering the Order and LineItems as another example:
Order and LineItems are related like this - For every order, there can be one or more lineItem.In this case, it doesnot make sense for the lineItem to exist without a order- Since the LineItem is tightly coupled with Order, hence it is a case of composition.
As for the code, it can be represented as :

Hope this helps.
Regards,
Sandeep Desai
vgdesai@bom3.vsnl.net.in

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56

  5. [This message has been edited by Desai Sandeep (edited May 03, 2001).]
 
Ram Nath
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Desai,
Thanks for the info i appreciate that.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic