序列图 UML if else 基于决策 [英] Sequence Diagram UML if else based on decision

查看:188
本文介绍了序列图 UML if else 基于决策的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以根据演员的决定在序列图中使用 if else,例如,如果演员认为价格足够合理,则执行 if,如果价格不合理,则执行 else 如下:

谢谢

解决方案

是的,但是...

组合片段 alt 可能有多个操作数,由水平线分隔并受到保护,可以通过像 [Reasonable price] 这样的交互约束,或者通过 [其他].如果我们按本书去做:

<块引用>

InteractionConstraint 显示在方括号中覆盖生命线,其中第一个事件发生将发生,位于该事件 (...) 上方.

这个图形说明很重要(即使我是第一个忘记它的人).因此,[合理的价格]应该覆盖你演员的生命线.在实践中,如果您不这样做,您的读者将隐式地进行映射,但图表可能会更加模糊.

为什么?

重要的是要意识到这个图形指令隐藏了一个更深层次的现实:在你的情况下,如果是演员主动开始相关的 alt 操作数并发送一些消息,那么演员应该能够评估 [合理价格] 是否适用.

我们应该记住,序列图描述了交互的可能执行路径(UML 术语中的跟踪",因为执行路径对太多人意味着太多事情):

<块引用>

交互是封闭分类器的行为单元.

交互的语义以一对跟踪集的形式给出.两个轨迹集分别代表有效轨迹和无效轨迹.

跟踪是一系列事件发生 (...)

并且由于序列图是由其生命线之间的交互构成的,因此应该根据可用的知识来评估守卫,即启动操作数的生命线的知识(以及在某些情况下对封闭分类器的知识)./p>

这不是明确的 UML 要求,而是考虑到封装原则和潜在可见性约束的逻辑推论.它使模型更有用并避免不切实际的期望.反过来说,如果参与的救生索都没有窗户可以看天空,看看天气是什么样的,那么守卫[美丽的天气]会是什么倾向?

结论

如果您的演员在图中有生命线,请确保守卫将其覆盖.

如果你的演员在图中没有生命线,这个守卫在语法上仍然是正确的.但问问自己,互动的哪个参与者可以同时知道价格并确定什么是合理的价格.

Is it okay having if else inside sequence diagram based on the actor decision, in example if actor think the price is reasonable enough then execute if, and if it is not reasonable price then execute else like this :

Thankyou

解决方案

Yes, but...

The combined fragment alt may have several operands separated by horizontal lines and guarded, either by an interaction constraint like [Reasonable price], or by an [else]. If we go by the book:

An InteractionConstraint is shown in square brackets covering the lifeline where the first event occurrence will occur, positioned above that event (...).

This graphical instruction is important (even if I'm the first to forget about it). Accordingly, [Reasonable price] should cover the lifeline of your actor. In practice, if you don't, your readers will do the mapping implicitly, but the diagram might be more ambiguous.

Why?

It is important to realize that this graphical instruction hides a deeper reality: in your case, if it's the actor who shall take initiative of beginning the relevant alt operand and send some message, then the actor should be able to evaluate if [Reasonable price] applies.

We should keep here in mind that the sequence diagram describes the possible path of execution ("traces" in UML jargon, because path of execution means too many things to too many people) of an interaction:

Interactions are units of behavior of an enclosing Classifier.

The semantics of an Interaction is given as a pair of sets of traces. The two trace sets represent valid traces and invalid traces.

A trace is a sequence of event occurrences (...)

And since the sequence diagram is made of interactions between its lifelines, the guards should be evaluated based on the available knowledge, i.e. the knowledge of the lifeline that starts the operand (and in some cases knowledge of the enclosing classifier).

This is not an explicit UML requirement, but a logical deduction considering the principle of encapsulation and the potential visibility constraints. It makes the model more useful and avoids irrealistic expectations. By antagony, what would be the leaning of a guard [beautiful weather] if none of the participating lifeline would have a window to look at the sky and see what the weather looks like?

Conclusion

If your actor has a lifeline in the diagram, make sure the guard covers it.

If your actor has no lifeline in the diagram, this guard would still be syntactically correct. But ask yourself which of the participant of the interaction could at the same time know the price and determine what is a reasonable price.

这篇关于序列图 UML if else 基于决策的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆