Reputation: 159
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.
Upvotes: 1
Views: 186
Reputation: 5673
In fact, I'd say that most cases of associations in models are neither aggregations nor compositions (both are forms of part-whole relationship types). For instance, the association between the classes Publisher
and Book
for assigning the books published by a publisher to this publisher is neither an aggregation nor a composition because the books published by a publisher are not parts or components of this publisher.
For implementing this bidirectional association, we use the two mutually inverse reference properties Publisher::publishedBooks
and Book::publisher
, as shown in the following class rectangles:
Notice that the multi-valued reference property Publisher::publishedBooks
is normally implemented by a list-valued property in Java.
I have explained how to use associations and reference properties in design models in my tutorial Managing Unidirectional Associations in a JavaScript Frontend Web App.
Upvotes: 1
Reputation: 24484
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.
Upvotes: 0