• 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

Difference between aggregation, association and composition

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can someone explain me the difference between aggregation, association and composition with an example within UML Context.
Regards,
Ashok
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Association
Association is fundamentally a "relationship" between classes. In its simplest form it is shown as a single line connecting two classes (for 3 or more associations you would use the UML concept of N-ARY associations) If the lines connecting two classes do not have any connecting arrows it means that the classes are jointly navigable, i.e one can navigate from one class to the other. A simple association would be :-
places
Customer--------------------Order

Rolenames can be added to the above and would translate to an attribute of the defined type. Code generation tools would generally do this automatically and prefix with "my", "an" "the", i.e
Works for
Employee---------------------------Company
worker employer

Would translate into the following Java Classes :-


Aggregation/Composite
These are just an advanced form of an association. They model whole/part contexts.

An aggregate relationship means that the "Part" can exist without the whole. An example of this would be :-
Portfolio---------------Stock
You could have many different "portfolios" in which "stock" could be a member of , in which case this is an aggregate relationship.

An example of a composition would be :-
Order-------OrderLine
i.e one order can have 1 or more order lines. If the order is removed, the order lines are destroyed also. A composite relationship means that the parts can have only one who. An example would be a Book (the whole) containing many parts (pages, index, contents page, cover etc). A book can have one and only one contents page --> Composite relationship. Composites are modelled via a dark diamond. The diamond appears on the "Whole".

HTH
 
Priya Patel
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just noticed that my "Spaces" were stripped out ..
so : "Places" is an association description for :-
Customer--------------------Order
"Customer places an Order"
and :-

"Employee Works for a Company"
Where "Worker" is a Rolename for Employee and
"Employer" is a Rolename for Company
 
Ashok Chakravarthy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks for the explaination.
Just to have more clarity, In your below example "Portfolio" has a relationship with "stocks" which can be called as association (of type aggregation). So when would we define as association and not an aggregation? Is it that only if it deal with whole/parts (car 'whole' contains engine,wheels as 'part') we consider to be of type aggregation. And in case we have customer placing an order, can we call it an association (of type composition customer <>---- order).
Do let me know if the above understanding is correct.
Regards,
Ashok

Originally posted by Priya Patel:
Association
Association is fundamentally a "relationship" between classes. In its simplest form it is shown as a single line connecting two classes (for 3 or more associations you would use the UML concept of N-ARY associations) If the lines connecting two classes do not have any connecting arrows it means that the classes are jointly navigable, i.e one can navigate from one class to the other. A simple association would be :-
places
Customer--------------------Order

Rolenames can be added to the above and would translate to an attribute of the defined type. Code generation tools would generally do this automatically and prefix with "my", "an" "the", i.e
Works for
Employee---------------------------Company
worker employer

Would translate into the following Java Classes :-
class Company
{
Employee myWorker;
}
class Employee
{
Company myEmployer;
}

Aggregation/Composite
These are just an advanced form of an association. They model whole/part contexts.

An aggregate relationship means that the "Part" can exist without the whole. An example of this would be :-
Portfolio---------------Stock
You could have many different "portfolios" in which "stock" could be a member of , in which case this is an aggregate relationship.

An example of a composition would be :-
Order-------OrderLine
i.e one order can have 1 or more order lines. If the order is removed, the order lines are destroyed also. A composite relationship means that the parts can have only one who. An example would be a Book (the whole) containing many parts (pages, index, contents page, cover etc). A book can have one and only one contents page --> Composite relationship. Composites are modelled via a dark diamond. The diamond appears on the "Whole".

HTH

 
reply
    Bookmark Topic Watch Topic
  • New Topic