如何在 UML 中对互斥属性进行建模?

发布于 2024-08-10 21:19:55 字数 804 浏览 8 评论 0原文

我正在 UML 中建立一个分析模型,当尝试在类图中表示对几个属性的约束时,我有点陷入困境。在下面的类中:

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

所有列出的属性都是布尔类型,最后两个属性 isBazisQuux 是互斥的。我该如何表明这一点?我不想使用临时注释——更加混乱。

我能在 UML 中找到的关于约束的所有内容似乎都将它们应用于关联,而不是属性。我可以将属性分解为关联的类,但它们是简单的布尔类型,因此类似这样的事情看起来有些过分:

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

在 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伴梦长久 2024-08-17 21:19:55

只有两个选项:将属性建模为与布尔数据类型的关联或使用 OCL 约束。

简化和更正后的(OCL 中的等于仅带有一个“=”)可能是: context SomeClassinv not isBaz=isQuux

顺便说一句,我不确定“互斥”概念对您的确切含义。这通常会实现 XOR(标准中关联的预定义约束),但随后您会使用 NAND。在您的模型中,两个属性是否有可能具有错误值? (我假设这在我的 OCL 约束中是不可能的)

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)

追我者格杀勿论 2024-08-17 21:19:55

我会考虑使用对象约束语言来描述它。

除了几次讲座之外,我从未真正使用过它,但我相当确定这就是您所需要的。

像这样的东西可能会表达您想要的条件:

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

This 演示文稿可能会给您一个很好的起点。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文