开发者

how to model mutually exclusive attributes in UML?

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?


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)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜