Page 1 of 1

XOR constraints on attributes by relationship

PostPosted: Wed 24 Sep 2014 01:33
by adi
I tried to find a way of adding a XOR constraint between 2 (works also between 3 or more?) attributes by relationship. There seems to be no information about this detail in the BOUML manual. As shown in attached project, I can "visually" show a {XOR} constraint between a "-automaticTransmission" and a "-manualTransmission" attributes by linking the text "{XOR}" to unidirectional association arrows, using "Anchor/Class association" simple lines. While this works as a visual detail, I would like to know if there is any way to implement the {XOR} condition as a defined logic condition, something that BOUML can translate in C++ code.
example with a {XOR} constraint on attributes by relationship.
(5.26 KiB) Downloaded 442 times

Re: XOR constraints on attributes by relationship

PostPosted: Wed 24 Sep 2014 10:27
by Bruno Pagès
The constraints are managed by Bouml, even I don't respect at 100% the norm

Because your constraint is between two relations you can define it at the class level or on one of the relations (editing the class or a relation)

By default the constraints are not shown in a class diagram, to show them you have to set the drawing setting "show information note" at the diagram level (or upper) or just for C_Car. This will show the note containing the constraint text (XOR ..), but the anchor will be made with the class (even the constraint will be for a relation), anyway after you can remove the anchor to the class then add new anchors to the relations.

There is no way to generate code from the constraint

Re: XOR constraints on attributes by relationship

PostPosted: Wed 24 Sep 2014 17:55
by adi
Dear Bruno, since I am just learning UML/BOUML, here are some stupid questions. It is no way to generate code from a diagram with this special {XOR} condition between two or more attributes because this bit of UML is not implemented in BOUML? I assume the {XOR} condition will be automatically discarded in this case?
Or I am wrong and UML is not supposed to translate this {XOR} stuff in code, it is supposed to discard it?

Cordialement à vous,

Re: XOR constraints on attributes by relationship

PostPosted: Thu 25 Sep 2014 19:13
by Bruno Pagès
Dear Adi,

In UML the constraints can be be written in OCL, or can be free text, OCL being a language it is possible to translate it in 'standard' language like C++/Java/...

Anyway the constraints may have several roles, including documentation purpose, and even it is for code production there are several possibilities. Considering the XOR between your two relations, do you want to produce assertions checking the XOR is true at execution time ? if yes where the assertion must be placed, each time you set one of the relation ? You may not want to produce assertion and for instance to reset a relation when you set the other, etc

Bouml doesn't manage OCL, so the content of the constraints is free, you can set them with OCL code or any other text. Because of that, and because there are several possible goals attached to the constraints the code generators do not consider them.