5

I have a hard time understanding the concept of association class as explained in UML 2.5 specification. The thing that confuses me the most is the following sentence taken from page 199:

NOTE. Even when all ends of the AssociationClass have isUnique=true, it is possible to have several instances associating the same set of instances of the end Classes.

As noted here: https://issues.omg.org/issues/UMLR-757 this single sentence seems to undermine the usefulness of the concept. At the same time, it makes pretty much every text explaining the concept written before 2.5 version of the UML spec obsolete – see for example the discussion here: UML association class - clarifying

But how can this actually work conceptually? Assuming all ends of the association class have isUnique=true, how can one have more than one instance of association class associating the same set of instances of the end classes, when isUnique property of member ends clearly forbids existence of such links?

I’ve always thought that an association class is just a regular association with extra attributes and/or operations. That interpretation seems to invalid now. So what exactly is association class? How can it have uniqueness independent from that of association member ends? There seem to be some unspoken multiplicity lurking somewhere (uniqueness is irrelevant property without maximum multiplicity higher than 1), but I can't figure out where.

Christophe
  • 68,716
  • 7
  • 72
  • 138
vrsio
  • 85
  • 5
  • 1
    Actually due to a missing glossary the term `isUnique` itself lacks a definition in the specs. I sent a bug report regarding a missing glossary several years ago. Nothing has happened. – qwerty_so Sep 26 '20 at 20:28
  • Yes, indeed, the introduction of non-unique association ends (and the corresponding multi-set-valued properties) in UML 2.0 made pretty much every text explaining the association class concept, or the underlying association concept, written before UML 2.0 obsolete. But that's normal in the evolution of a spec. – Gerd Wagner Sep 30 '20 at 12:35

1 Answers1

6

In very short

Indeed, this is not super-clear and would deserve a better explanation. To make it short: it’s just a consequence of the lack of integration in the dual semantics defined for the association class.

Detailed explanation

What is uniqueness for an association

According to UML 2.5.1 section 11.5.3.1, page 197:

When one or more ends of the Association have isUnique=false, it is possible to have several links associating the same set of instances.

We can deduct using logical contraposition that:

If it is not possible to have several links associating the same set of instances, all ends of the association have isUnique=true.

So we'd expect this to apply to an assocation class as well, since the association class is also an association.

Association classes are two distinct things at the same time

According to UML 2.5.1 section 11.5.3.2:

An AssociationClass is both an Association and a Class, and preserves the static and dynamic semantics of both.

So, an association class is not just "an association with extra attributes". If it were that simple, the association class could perfectly be a generalization of an association: the specialized association would just inherit the extra attributes. But this is explicitly prohibited page 199:

An AssociationClass cannot be a generalization of an Association or a Class.

because any specialization into a class would loose the association semantics, and any specialization into an association would loose the class semantics.

And this duality, is the cause of our issue.

Impact of this duality on instances

According to UML section 11.5.3.2, page 199 (formatting from me):

An instance of an AssociationClass has the characteristics both of a link representing an instantiation of the AssociationClass as a kind of Association, AND of an object representing an instantiation of the AssociationClass as a kind of Class.

If isUnique=true for all association ends, the instances of the association are guaranteed to be unique. Remind however that the association is only about tuples made out of the association ends:

An Association declares that there can be links between instances whose types conform to or implement the associated types. A link is a tuple with one value for each memberEnd of the Association, where each value is an instance whose type conforms to or implements the type at the end.

However, nothing in the specs requires that the class instantiation (object) representing the association instantiation needs to be unique.

Imagine for example, that we have an association class between class A and class B, and a and b are instances of these classes. Imagine that the association ends have isUnique=true. This means that there can be only one tuple (a,b) since the association is guaranteed to be unique.

Let P be a property of the association class, and let (a,b,p1) and (a,b,p2) be two instances of the class in the association-class. The class knows no association-ends: from the point of view of the class, there is no unicity requirement. And from the point of view of the association, we have only one tuple (a,b) , so it's ok as well.

The NOTE just explains that this (unfortunate and ambiguous) situation is possible.

Are there contradictions or inconsistencies?

Formally, there is no contradiction. This is the result of the way the association class is defined: a class and an association at the same time, without further defining the relationship between the respective instances.

But this creates some issues in regard of the semantics of associations having non-unique ends:

When one or more ends of the Association have isUnique=false, it is possible to have several links associating the same set of instances. In such a case, links carry an additional identifier apart from their end values.

More precisely, this makes the the association-class with unique ends useless, since the same result can be achieved with non-unique ends:

  • for a simple association with non-unique ends, you can have duplicates, i.e. several links associating the same instances of the association ends that are distinguished with an additional identifier.
  • for association classes with unique ends, according to the note you can have duplicates, i.e. several objects (class instances) corresponding to a link made of unique association ends (association instances).
  • for an association-class with non-unique ends, you could have duplicates, i.e. several object instances correspond to the same set of member ends. It makes no difference if you interpret this as several links associating the same instances of the association ends, each associated with a single object, or, if you interpret this as one link associating a unique set of instances of the association end, that would be each be associated to mutliple object instances.

IMHO, this is unfortunate:

  • it does not match our mental model in which an association class with all association ends having isUnique=true should have a unique object instance of the class for a unique combination association ends. This clearly goes against the principle of least astonishment: I started with deny and it took me a while to accept this, since it was so terribly different from the traditional ways to implement association classes.
  • two different models, one with unique association ends, and one without could in fact express the same situation.

A simple solution to this issue would be to require a unique class instance (object corresponding to the association class) to correspond to a link that uniquely associates association ends. In that way, unique association ends would imply unique association object, without requiring other changes to the UML specs.

Christophe
  • 68,716
  • 7
  • 72
  • 138
  • Phew. Long answer for a "simple" question. Sometimes it's just better to just use practical, proven approaches (as the OP linked in one answer) and not dive into the egghead's definitions. UML is not perfect but definitely has more pros than cons. Horse sense is best. – qwerty_so Sep 27 '20 at 07:37
  • @qwerty_so ;-) yes it’s a long answer to a definitively not so simple question. I could have simplified into “it’s just a consequence of the lack of integration in the dual semantics defined for the the association class”. But since I had myself, not so long ago, dived into the definitions and wondered how this flaw could be improved, it was the opportunity to share this analysis. – Christophe Sep 27 '20 at 08:10
  • Thanks for sharing your analysis. One nitpicky question about the second inconsistency listed: why do you assume that unique identifier of duplicate associations is not a part of the object? Wouldn’t association class model element inherit said identifier from association element? – vrsio Sep 27 '20 at 10:25
  • 1
    @vrsio you're welcome. This assumption is based on the wording "*In such a case, **links carry an additional identifier** apart from their end values.*", but the tuples representing the links are something conceptual and nothing seems foreseen in the class semantic to deal with such thing. It doesn't seem to be defined as a property for example. – Christophe Sep 27 '20 at 11:28
  • @Christophe Your last section is hard to understand since you are using the wrong term of "non-unique associations". According to the spec the adjective "non-unique" does not apply to associations, but to association ends. Also, it doesn't make sense to say that an association with non-unique ends "can have duplicates that are distinguished with an additional identifier". Where do they say this? A non-unique end simply means that the collection value of the corresponding property is a multi-set instead of a set, so the association's population (its collection of links) is a multi-set as well. – Gerd Wagner Sep 29 '20 at 21:23
  • @GerdWagner Thank you for the opportunity to clarify an unfortunate wording. With "duplicates" and "non unique associations", I meant "multiple links for the same association ends". In a similar way, with "duplicates distinguished by an additional identifier", I meant "multiple links for the same association ends set appart with an additional identifier". I also use ambiguously the term "instance" for both the link that represents the association, and the instance of the class. And the additional identifier is not a property but an abstract construct to differentiate links. – Christophe Sep 29 '20 at 21:40
  • @GerdWagner And indeed, I like your wording saying that the corresponding property is a multiset. But we are speaking of potentially several related properties, "instances" seemed to be more accurate. The wording of the note itself uses the "several instances associating the same set of instances of the end Classes", where "the same set of instances of the end classes" is in fact the link, and "several instances associating...." is in fact several objects instantiating the association class. – Christophe Sep 29 '20 at 21:53
  • @Christophe But in the case of a non-unique association end, there is no "additional identifier" for setting apart identical links! Or do you refer to the case of an association class with unique association ends but still having several identical links? – Gerd Wagner Sep 29 '20 at 22:00
  • @GerdWagner according to the last quote, there is an additional identifier (not in the object but in the tuple representing the link) when the same set of instances occur several time. But you are right, such an identifier is not mentioned (and it does not make sense) for combinations that are distinct. I’ll try to find a better formulation fir this last section and post a comment when it’s done: I value very much your critical reading and constructive remarks. – Christophe Sep 29 '20 at 22:10
  • @Christophe My understanding of the UML 2.0 concept of non-unique association ends is based on the article "On the Semantics of Associations and Association Ends in UML" https://ieeexplore.ieee.org/document/4123326. If you cannot access it, send me an email (g.wagner@b-tu.de) and I'll mail you the PDF. – Gerd Wagner Sep 30 '20 at 12:29
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/222304/discussion-between-gerd-wagner-and-christophe). – Gerd Wagner Sep 30 '20 at 12:39