gpt4 book ai didi

uml - 如何在 UML 中设计一个又一个决定(菱形)的决定?

转载 作者:行者123 更新时间:2023-12-04 15:41:05 26 4
gpt4 key购买 nike

我现在正在 ArgoUML 中设计 UML 事件图。
我知道如果我想设计如下条件:

if(condition) {
doTrueAction();
} else {
doFalseAction();
}

它可以在 UML 事件图中完成,如下所示:
enter image description here
但是如果我们在前一个决策的输出中有另一个条件呢?像这样:
if(condition) {
if(condition2) {
condition2TrueAction();
} else {
condition2FalseAction();
}
}else{
conditionFalseAction();
}

enter image description here

如您所见,conditionTrueOutput 正在同时输出和条件。在我看来,设计被打破了。
编辑:或者我应该使用 fork 元素而不是决策(菱形)元素?

enter image description here

我想知道如何正确设计它。有什么规律吗?

最佳答案

你的想法有一个错误的假设。一个 Decision没有输出。它只是有条件控制流离开它。每个人都可以受到某种条件的保护。这个守卫写在方括号中:

enter image description here

请注意,我没有写(隐式)[true]守卫第一次测试(编辑时比较草率,但实际上可以省略)。

编辑 我的第一个虽然你的图表有另一个缺陷,即 Action 没有控制流出去是不正确的。实际上,上层建筑声明缺少传出控制流相当于 FlowFinal处理后 Action .所以你的图表在这里是正确的。

关于您的编辑:正如评论所说,这是为了并行延续。嵌套条件需要如上所示。

编辑 2 正如 Ister 在评论中指出的,Decision可以拥有的不仅仅是 ifelse控制流出去,但是一个大于 1 的任意数字。UML 2.5 状态在 p。 388:

If exactly one target of an unblocked outgoing edge accepts the token, then the token traverses the corresponding edge and all other offers are withdrawn. If multiple targets accept the token simultaneously, then the token traverses only one of the edges corresponding to the accepting targets, but which one is not determined by this specification.

In order to avoid non-deterministic behavior, the modeler should arrange that at most one guard evaluate to true for each incoming token. If it can be ensured that only one guard will evaluate to true, a conforming implementation is not required to evaluate the guards on all outgoing edges once one has been found to evaluate to true.

For use only with DecisionNodes, a predefined guard “else” (represented as an Expression with “else” as its operator and no operands) may be used for at most one outgoing edge. This guard evaluates to true only if the token is not accepted by any other outgoing edge from the DecisionNode.

关于uml - 如何在 UML 中设计一个又一个决定(菱形)的决定?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39557631/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com