Ashok Chakravarthy

Greenhorn
+ Follow
since Feb 03, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ashok Chakravarthy

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

Hi,
Can someone explain me the difference between aggregation, association and composition with an example within UML Context.
Regards,
Ashok