如何在 UML 中设计一个接一个的决策(菱形)?
How to design decision after decision (diamond) in UML?
我现在正在用 ArgoUML 设计 UML Activity 图。
我知道如果我想设计这样的条件:
if(condition) {
doTrueAction();
} else {
doFalseAction();
}
可以在 UML activity 图中完成,如下所示:
但是,如果我们在先前决策的输出中有另一个条件怎么办?像这样:
if(condition) {
if(condition2) {
condition2TrueAction();
} else {
condition2FalseAction();
}
}else{
conditionFalseAction();
}
如您所见,此处同时输出 conditionTrueOutput 和条件。在我看来,设计被打破了。
编辑: 或者我应该使用 fork 元素而不是 decision(菱形)元素?
我想知道如何正确设计它。有什么规定吗?
看来你的设计是连贯的,但不是UML图。我假设您将 activity 图 与 序列图 .
混合在一起
您的图看起来像序列图,但它试图表示与 activity 图相关的信息。
我建议你这个web site来研究两个图之间的差异,希望它能对你有所帮助。
相反,通过尝试使用您的设计,我建议您在两个条件 2 之前插入另一个 条件(例如 SecondConditionAction)。
你的想法有误。 A Decision
没有输出。它只是有条件控制流离开它。每个人都可以受到特定条件的保护。这个守卫写在方括号里:
请注意,我在第一次测试后没有写(隐含的)[true]
守卫(而是编辑时草率,但实际上可以省略)。
编辑 我首先认为您的图表还有另一个缺陷,即操作没有控制流出去是不正确的。实际上 Superstructures 指出,在处理 Action
之后,丢失的传出控制流等同于 FlowFinal
。所以你的图表在这里是正确的。
关于您的编辑:正如评论所说,这是为了平行延续。嵌套条件需要如上所示。
Edit2 正如 Ister 在评论中指出的那样,Decision
可以不仅仅包含 if
和 else
控制流,但是大于 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.
我现在正在用 ArgoUML 设计 UML Activity 图。 我知道如果我想设计这样的条件:
if(condition) {
doTrueAction();
} else {
doFalseAction();
}
可以在 UML activity 图中完成,如下所示:
但是,如果我们在先前决策的输出中有另一个条件怎么办?像这样:
if(condition) {
if(condition2) {
condition2TrueAction();
} else {
condition2FalseAction();
}
}else{
conditionFalseAction();
}
如您所见,此处同时输出 conditionTrueOutput 和条件。在我看来,设计被打破了。
编辑: 或者我应该使用 fork 元素而不是 decision(菱形)元素?
我想知道如何正确设计它。有什么规定吗?
看来你的设计是连贯的,但不是UML图。我假设您将 activity 图 与 序列图 .
混合在一起您的图看起来像序列图,但它试图表示与 activity 图相关的信息。
我建议你这个web site来研究两个图之间的差异,希望它能对你有所帮助。
相反,通过尝试使用您的设计,我建议您在两个条件 2 之前插入另一个 条件(例如 SecondConditionAction)。
你的想法有误。 A Decision
没有输出。它只是有条件控制流离开它。每个人都可以受到特定条件的保护。这个守卫写在方括号里:
请注意,我在第一次测试后没有写(隐含的)[true]
守卫(而是编辑时草率,但实际上可以省略)。
编辑 我首先认为您的图表还有另一个缺陷,即操作没有控制流出去是不正确的。实际上 Superstructures 指出,在处理 Action
之后,丢失的传出控制流等同于 FlowFinal
。所以你的图表在这里是正确的。
关于您的编辑:正如评论所说,这是为了平行延续。嵌套条件需要如上所示。
Edit2 正如 Ister 在评论中指出的那样,Decision
可以不仅仅包含 if
和 else
控制流,但是大于 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.