0

I'm working up an analysis model in UML, and I'm a bit stuck when trying to represent a constraint on a couple of attributes in a class diagram. In the following class:

+-----------+
| SomeClass |
+-----------+
| isFoo     |
| isBar     |
| isBaz     |
| isQuux    |
+-----------+

all the listed attributes are Boolean types, and the final two, isBaz and isQuux, are mutually exclusive. How do I indicate that? I'd rather not use an ad-hoc note -- more clutter.

Everything I can find about constraints in UML seems to apply them to associations, not attributes. I could break the attributes out into an associated class, but they're simple Boolean types, so something like this seems like overkill:

+-----------+
| SomeClass |
+-----------+ 0..1   isBaz   1 +-------------------+
| isFoo     |------------------| ThereCanBeOnlyOne |
| isBar     |      |           +-------------------+
|           |      |{NAND}     | isBaz             |
|           |------------------| isQuux            |
+-----------+        isQuux    +-------------------+

What's the 'correct' way to model mutually exclusive attributes in UML?

Val
  • 2,291
  • 7
  • 34
  • 63

2 Answers2

1

I would look into using Object Constraint Language to describe it.

I've never really used it beyond a couple lectures, but I'm fairly sure this is what you need.

Something like this may express the condition you want:

{context SomeClass
inv isBaz==True implies isQuux==False
inv isQuux==True implies isBaz==False}

This presentation may give you a good starting point.

chrisbunney
  • 5,819
  • 7
  • 48
  • 67
  • Yes -- the {NAND} in my 2nd diagram is shorthand for an OCL constraint; Scott Ambler uses that in an example. I scanned the preso you linked to. Mostly the constraints are applied against associations, but in a few places they just float around and reference attributes. I suppose I can put your proposed expression in an annotation that points to the class. – Val Nov 12 '09 at 01:44
1

There are only two options, model the attributes as associations with the boolean data type or use an OCL constraint.

A simplified and corrected (equals in OCL goes with just one "=") could be: context SomeClassinv not isBaz=isQuux

Btw, I'm not sure about the exact meaning for you of the concept "mutually exclusive". This usually imples an XOR (predefined constraint on associations in the standard) but then you use a NAND. Is it possible in your model that both attributes have a false value? (I'm assuming this is not possible in my OCL constraint)

Jordi Cabot
  • 8,058
  • 2
  • 33
  • 39
  • thanks, great clarification. Yes, in my model, isBaz and isQuux are really 'Operating Expense' and 'Major Operating Expense' The parent object, a Contract, can be classified as one, the other, or neither (both false), but not both. – Val Nov 14 '09 at 19:16