'Is it possible to link a XOR constraint to another XOR constraint in UML?

Here is an example of what I want to do: Let's say I have 5 classes, I would like to express the constraint that we can have an instance of class "B" or/and "C" linked to "A", if so we cannot have anything else, and if we don't have any instance from those classes, we only can have one instance of class "D" or "E".

enter image description here

I checked on the official documentation here: https://www.omg.org/spec/UML/2.5.1/ But the part on XOR constraint is very limited. As it's not explicitly described that we cannot, I assume it's possible, but i'm not sure.

Thank you for your help.



Solution 1:[1]

In UML Class Diagrams, all kinds of constraints can be included in the form of invariants, which are logical conditions that can be expressed either in plain English or in the Object Constraint Language (OCL) within a constraint rectangle/box that is attached to a class (or association).

Your constraint could be added in this way (attached to your class A), like so:

enter image description here

But your constraint cannot be expressed in the way you have tried to express it. The special dashed line notation for disjunctive association constraints cannot be combined in this way.

Solution 2:[2]

Syntactically speaking, a constraint is a PackagedElement, which is an Element, and can therefore also be subject of other constraints. So the diagramme is valid.

But...

Semantically however, this would not be very useful. Because, the constraint has to be true. So A-D {xor} A-E means that there is either a link to D or to E, but not both, but the constraint itself would always be true. This implies that there is no A-C and no A-B, never, so that these associations are completely useless.

The easisest way would be to give a linked attribute name to each of the potentially related class (e.g. b, c, d, e), and express the exclusions in a single constraint.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Christophe