How to draw a constraint like this in PlantUML
1 Answers
PlantUML technique 1
There's no easy way to do this, because PlantUML doesn't give a syntax that allows to relate lines. The best you could achieve is this:
You can achieve this by association two elements and creating a pair of the same elements, e.g. (Account, Person)
.This creates a composite element with two line segments related by the dot. You can then relate both pairs with ...
to get a dotted line, and name this relation by adding a trailing : {xor}
:
@startuml
skinparam style strictuml
class Account
class Person
class Corporation
Account -- Person
Account -- Corporation
(Account,Person) ... (Corporation,Account) : {xor}
@enduml
PlantUML technique 2
Another alternative is to use a comment box to include the constraint. This is by the way the usual notation when attaching a constraint to an element. You can then combine the pairing techniques with a note attached to each of the pairs (source: this tutorial in French):
@startuml
skinparam style strictuml
class Account
class Person
class Corporation
Account -- Person
Account -- Corporation
note "{xor}" as N #white
(Account,Person) .. N
N .. (Account,Corporation)
@enduml
UML Design improvement
In reality such constraints should be minimized as much as possible, because they often only hide a missing abstraction. I would therefore not use the {xor} and rather consider :
By the way, the grouping of multiple inheritance relations is also achieved with pairing, as explained here.

- 68,716
- 7
- 72
- 138
-
The dots in the association mids don't look like `strictuml`though ;-) – qwerty_so Nov 22 '22 at 22:31
-
@qwerty_so I can only agree. As far as I understood, this dot was initially introduced for modelling association classes (A,B) .. C and it looks less shocking in this context. Using it for grouping specialization is already a trick that reuses(misuses?) the notation for another purpose. On the other side, I find it sad that there is no better and more natural way to show generalization groups in plantuml... – Christophe Nov 22 '22 at 23:05
-
Well, mainly it's a drawing tool. Not too bad though and certainly has its (good) purpose. – qwerty_so Nov 22 '22 at 23:49
-
1[This](http://www.plantuml.com/plantuml/uml/ROwngi9044Nx_OfBgeINv0DUbSThB2p4FrWteovcTyBi10tYlnlC5Wes0vTxpd2xf5Pq2eFPqb6XZBq_dHMz5tBgESAaYu-Z5HkGT1vekUBTIzduda1Xr1c1me4amRZ1feG_vtYAcjDkQJZcyCyoijZrT-RGD2X--1f9Yan_xJxbCXFrQbHesnOetvWw4nL-SR-nF4n7iL-cFm40) is closer to OP's diagram. – Fuhrmanator Nov 23 '22 at 01:53
-
The first option is "correct" – user877329 Nov 23 '22 at 16:36