UML Class relations: Association, Aggregation and Composition
Tagged:

I've always had a problem understanding the difference between an association and an aggregation.
Curiously, the difference between composition and aggregation never caused me any problem. You just have to think that when the "whole" gets deleted; if the "parts" still exist then it is a aggregation, if they also get deleted then it is a composition.

Back to the problem: in theory I knew that an aggregation represented an "has a" relationship, but as most of my classes had many other classes as attributes I thought it was strange that all of them were represented by a aggregation relationship.

After some research these are my conclusions:

  • If you have another class as an attribute then you do have an aggregation (or composition) relationship.
  • An association means that a class "uses" the other class (like in a parameter of an operation).

Here is an example I've done to demonstrate it better:

As it is possible to see, the motor doesn't have any "has a" relationship with the fuel class. It only uses it in a operation to accelerate the motor, therefore it is a association relationship. The same happens to the association between the Fuel class ant the FuelPump class. In this case the Fuel class is present in the return type for the accelerate operation.

Just a practical rule to never forget (a little of topic): If in the code you change a class, the only classes affected by this modification are the ones that have any relationship with the modified class.

Determine association, aggregation and composition

Hi,

Thank you so much for pointing out how to know difference between an association and aggregation! Your info is really useful.

I have written a diagram to determine the relationship for abstract objects: http://yanny0808.blogspot.com/2010/08/uml-association-aggregation-compos....

I'm still studying the UML class diagram, so your posting is really helpful for me!

Difference between Association, Aggregation and Composition

Hi,

I was breaking my head most of the times without knowing the clear difference between Association, Aggregation & Composition. Here you have given a clear picture. Thanks for your effort.

Need a small clarification from you. Why Diesel & Petrol classes are having dotted line(--->) relationship with fuel? ---> will make a feel like Dependency between them. Am i correct? or missing anything here?

Regards,
Rousseau Arulsamy

its a generalization

its a generalization

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions. It will also improve your math skills :P