How to model a covariant association-class in UML?

Preliminary remark: First I’d like to than Bruno and Axel for their respective answers, that put me on the right track. Nevertheless digging further based on their indications, I stumble accross an even simpler solution and supporting references. As it’s useful and following Bruno’s suggestion I’ve finally decided to post it as ananswer.

Can simple associations be specialized?

In my question, I considered the case of an association class, because I thought that only classes could be specialized. But in fact, simple associations can be generalized as well.

First of all, an association is itself a already a classisifier according to UML 2.5:

Section 11.5.1: An Association classifies a set of tuples representing links between
typed instances. An AssociationClass is both an Association and a Class.

A classifier can be specialized:

Section 9.2.3.2: Generalizations define generalization/specialization relationships between Classifiers.

The notation is as follows (I spare you the specs details, and I must admit that 2 weeks ago I would have claimed “nonsense” if I’d have seen this):

enter image description here

What does association specialization mean?

The semantics for associations specialization are well defined (highlights from me:

Section 11.5.3.1 (p.198): (…) In the case of Associations, specialization means that a link classified by the specializing
Association is also classified by the specialized Association
. Semantically this implies that
sets calculated by eliminating duplicates from the collections representing the ends of the
specializing Association are subsets of the corresponding sets calculated by eliminating
duplicates from collections representing the ends of the specialized Association; this
fact of subsetting may or may not be explicitly declared in a model
.

So, without telling anything about the association ends, the specialization implies that the spcializing association is a subset of the general association. Explicit subsetting is optional:

enter image description here

And what about association classes?

Association classes are both, an association and a class. The UML specifications clarify that both are classifiers and that the properties
of the metamodel are not dubplicated. So it’s one and the same. The specialization applies to both at the same time:

Section 11.5.3.2:(…) the specialization and refinement rules defined for Class and Association are also applicable to AssociationClass.

Important remark: an association can generalize another association, an association class can generalize an association class, but “an AssociationClass cannot
be a generalization of an Association or a Class”
), and the way we generally understand this is not valid:

enter image description here

Conclusion

When taking rigorously the UML specifications, it appears that my diagram with the simple specialization between the association classes, is correct,
unambiguous and expresses the intented semantic. Alex’s answer proposed to explicitly declare the implied subsetting: this is valid, but it is
not required.

enter image description here

Note that there is a subtle difference: the generalization/specialization are about the association itself, whereas the subsetting is about the association ends.

Additional insights:

Leave a Comment