Search code examples
oopumlaggregation

How can we have an Association that is not an Aggregation?


Aggregation is defined as a special case of association. However, any association that is not implemented as a field (like having a relationship through method parameters) are being described as "use" relationship.

So, is it possible to have an association that is not aggregation or composition? If yes, I need a code example for such a case, please.


Solution

  • Shared aggregation (empty diamond) is not defined strictly in the UML standard. So, it is not easy to find a situation, where you can not use it.

    But it is explicitely forbidden to use it for both sides of association. So, if you have relation many to many, you have to show it on class diagram as many to many association with none aggregation. Of course, you can show it as TWO shared association, but it is not our target, is it? :-)

    As for code, if people visit many courses and courses are visited by many people, make a list "courses" for Person class and a list "visitors" for Course class.

    Of course, on the other side, you always can use none instead of shared for any shared association, it is at your wish and up to rules of your place of work. But I don't know these rules, sorry :-). But surely, nobody will make you to use aggregation for 1 to 1 association.