Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How works {XOR} constraint in UML?

I have some doubts about how correctly we can use {XOR} constraint in UML.

enter image description here

I understand how it works in two different ways. Which one is correct?

  1. The xor constraint applies to the association. (either: an object of type A may be associated with 1 object of type C; or: an object of type A may be associated with zero or 1 object to type B; or: object A could be just by itself because we have [0..1] near B).

  2. The xor constraint applies to the link (either: an object of type A must be associated with exactly one object of type C; or: an object of type A must be associated to exactly one object of type B).

like image 705
DM14 Avatar asked Nov 29 '16 13:11

DM14


1 Answers

After many years I have to fix this answer (though I got many upvotes for it).

The {XOR} means that class A must have either an association to B or to C but not to both or none. That means in one case you have A * - 0..1 B and in the other case it's A 0..1 - 1 C. Both are legal constructs per se. Only here it is that A will play two exclusive roles.

This is a purely academic construct, so what it means in practice is completely open. It would be more meaningful (and helpful) if such examples from tutorials/classes would have some real world connection.


Old (wrong) answer

This is simply wrong (or a puzzle). You need exactly one C to be associated with A. But then, due to the XOR you may not associate B. Which means: the B relation is always 0 and you could as well leave it away.

Maybe (!) someone has put the multiplicity on the wrong side. If you swap them, it would make sense. If you use real names rather than A, B, C you could guess from the context.

like image 117
qwerty_so Avatar answered Sep 19 '22 11:09

qwerty_so