转到序列图中?

Lok*_*wal 6 uml sequence-diagram

如何在序列图中显示 goto 语句。

例如,在下图中,一旦“睡眠直到保留期”到期,我想将控制权交回“is_item_inventory_onhold_state(item_id)”语句。我怎样才能显示这是一个图表?

在此输入图像描述

我正在使用https://sequencediagram.org/来创建这些图表。

为生成上图而编写的代码:

title Item Executor

loop  for each item in a list 
Client->ItemExecutor: execute(item)

ItemExecutor -> ItemStateService:is_item_inventory_onhold_state(item_id)

alt True - Item state is on hold
ItemStateService -->ItemExecutor: True
ItemExecutor ->ItemExecutor: sleep till hold period 

goto  ItemExecutor -> ItemStateService:is_item_inventory_onhold_state(item_id)

else False - Item is not in Held State
ItemStateService -->ItemExecutor:False
ItemExecutor ->ItemExecutor: do_something()

end

ItemExecutor ->Client : Acknowledge
end 
Run Code Online (Sandbox Code Playgroud)

Axe*_*uer 7

序列图中不支持 Goto(有充分的理由)。loop使用 a和 a的组合break。请参阅此图:\n在此输入图像描述\n sequencediagram.org/Item Executor

\n\n

equencediagram.org/Item Executor(带有执行规范)

\n\n

关于此图的一些注释

\n\n
    \n
  • 留下break-fragment紧邻的片段。因此它必须直接包含在loop-fragment. 如果它位于 alt-fragment 内,则仅留下该片段。
  • \n
  • 和片段alt都不opt使用guard. 发生的片段是通过reply具有特定的消息的出现来选择的return-value的出现来选择的。如果你想使用守卫,你必须将返回值分配给局部变量。这将发生在替代片段上方(见下图)。
  • \n
  • 返回值显示前带有冒号。消息名称将在其前面,但是当它很明显时可以省略(就像这里一样)。
  • \n
  • execution specifications(有时称为“激活”)仅在有助于提高可读性的情况下显示。与普遍看法相反,它们不是强制性的。
  • \n
  • UML 不知道每个循环。因此我添加了迭代器操作。术语“对于列表中的每个项目”不是条件guard。如果你想避免拼写出迭代器,你可以使用一个 - 语义自由 -comment附加到循环。为此滥用布尔保护是没有意义的。如果你想要一个正式的定义,你必须添加你自己的构造型\xc2\xabfor each loop\xc2\xbb
  • \n
  • 我假设ItemExecutorItemStateService是类名。它们需要前面的冒号来将它们与角色名称区分开。当然,如果角色名称和类名称相同,您的图表可能是正确的。
  • \n
  • “确认”消息只是消息reply的消息execute。因此,它将具有相同的名称(此处省略)。
  • \n
  • 在具有执行规范的版本中,绘图工具不允许 的结尾与 的结尾execution specifications重合,而这本来是正确的。send eventsreply-messages
  • \n
\n\n

alt和片段的防护示例break(摘录):\n有警卫\ nequencediagram.org/ItemExecutor(带有执行规范和防护)

\n