Search code examples
architectureconstraintsumlclass-diagram

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

  • 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.