1

I have some doubts about which relationships i'm going to use in my class diagram. I know that I can use a general association (using a association line) or more specifc associatons like aggregation or composition. I already know the definition of aggregation and composition but my question is:

  1. when I will need to use a general association and when I will need to use a more specific association?
  2. There is some rule for that?
Vinicius
  • 151
  • 6
  • I'm not an expert but I'd say that general associations could be used for high-level class diagrams while aggregation/composition could be used for low-level detailed diagrams. – Baderous Jan 05 '16 at 14:09
  • 2
    Possible duplicate of [Difference between association, aggregation and composition](http://stackoverflow.com/questions/885937/difference-between-association-aggregation-and-composition) – qwerty_so Jan 05 '16 at 14:22
  • @Baderous That is not how it works. Both are used at the same level. – Geert Bellekens Jan 06 '16 at 03:24

2 Answers2

5

If your only concern is to be UML compliant, you are free to choose which type of association you use. However, a best practice is to make a decision about which types of association you use in your project and use them consistently.

My advice would be to use the general association and the composite aggregation, but not the shared aggregation. Use composition always if one class has responsibility for the existence of its associated class (by definition of composite). If there is a weaker kind of aggregation, just draw a general association.

Alternatively, you could decide to only use the general association. This option is preferred for example if your audience is not used to UML and you don't want to explain the more specific forms of association to them.

www.admiraalit.nl
  • 5,768
  • 1
  • 17
  • 32
3

When you are drafting, use unspecified relationships. When you start to make the diag more concrete, write number on its ends, specify arrow ends, name the ends, put shared/composite diamonds and points on the ends.

Notice - aggregation can be: shared, composition or none. To name shared aggregation simply aggregation is bad practice, against UML standard.

Gangnus
  • 24,044
  • 16
  • 90
  • 149
  • 1
    Oh, is it? I always used the term aggregation instead of shared? Where is that written that it should be named shared? – qwerty_so Jan 05 '16 at 16:39
  • @ThomasKilian In the UML standard documentation. I think, it is a serious authority? :-) Of course, there is no word about 'shared' being used INSTEAD of something, simply as I said, none-shared-composition values of the aggregation parameter are set.... And I would add to it, that is logical - if you use "aggregation" in place of shared, then what parameter do these three terms switch? "Aggregation" as one of states of "aggregation"?... I would like to know, what f... tool had first used that obviously incorrect term and perplexed so many people, for I know, it is quite widely used. – Gangnus Jan 06 '16 at 08:14
  • @ThomasKilian, see page 110 of the UML 2.5 spec. – www.admiraalit.nl Jan 06 '16 at 09:08
  • @www.admiraalit.nl Thanks to both of you for the clarification! – qwerty_so Jan 06 '16 at 09:12
  • I looked into UML 1.5 and they use terms like `(i.e., it is not an aggregation or composition).` very often. No word about `shared aggregation`. So that has been introduced in a later version then. – qwerty_so Jan 06 '16 at 13:28
  • @ThomasKilian Like what? use of GT and LT is possible by HTML codes only... The current UML version is 2.5. That is 10 versions ahead. And UML2 is really different from UML1... BTW, since 2.5 they have greatly improved the documentation itself. – Gangnus Jan 06 '16 at 15:24
  • I was just digging where the term comes from. And it wasn't a tool but the old specs. IDC about proper formatting in comments. Use your brain to imagine the citation I intended to highlight. – qwerty_so Jan 06 '16 at 15:28
  • @ThomasKilian I see, and I am grateful. But my brains are too weak to guess the missed word, sorry. Maybe, that theme deserves a special question on Programmers. – Gangnus Jan 06 '16 at 15:46
  • Doesn't the citation appear as code (highlighted)? I thought, this would be obvious. Probably I should have used dbl-quotes :-/ – qwerty_so Jan 06 '16 at 17:37
  • @ThomasKilian Yes, sorry. I don't see very well and the font difference is too little. And I thought, before the parenthesis there should be something in angle brackets... Thank you. So that is OMG itself who is guilty in that nonsense "aggregation" of type "aggregation". There were some biologsts among the authors of the old standards, I think. Lupus Lupus. :-) – Gangnus Jan 07 '16 at 07:32