gpt4 book ai didi

uml - 在序列图中转到?

转载 作者:行者123 更新时间:2023-12-03 20:16:01 27 4
gpt4 key购买 nike

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

例如,在下图中,一旦“ sleep 直到保持期”到期,我想将控制权交还给“is_item_inventory_onhold_state(item_id)”语句。我怎样才能证明这是一个图表?

enter image description here

我正在使用 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

最佳答案

序列图中不支持 Goto(有充分的理由)。使用 loop 的组合和 break运算符。看这张图:
enter image description here
sequencediagram.org/Item Executor

sequencediagram.org/Item Executor (with Execution Specifications)

此图的一些注释

  • break-fragment离开立即封闭的片段。因此它必须直接包含在 loop-fragment 中。 .如果它在 alt-fragment 中,则只剩下这个片段。
  • 两个altopt片段不使用 guard .发生的片段由 reply 的发生选择。带有某return-value的消息.如果要使用 guard ,则必须将返回值分配给局部变量。然后这将发生在 alt-fragment 之上(见下图)。
  • 返回值以前面的冒号显示。消息名称会在此之前,但是当它很明显时可以省略(就像这里一样)。
  • execution specifications (有时称为“激活”)仅在有助于提高可读性的地方显示。与流行的看法相反,它们不是强制性的。
  • UML 不知道每个循环。因此我添加了迭代器操作。术语“对于列表中的每个项目”不是 guard健康)状况。如果你想避免拼写迭代器,你可以使用 -semantic free - comment附加到循环。为此滥用 bool 值守卫是没有意义的。如果你想要一个正式的定义,你必须添加你自己的原型(prototype) «for each loop»
  • 我假设 ItemExecutorItemStateService是类名。它们需要前面的冒号来区分它们与角色名称。当然,如果角色名称和类名称相同,则您的图表可能是正确的。
  • “确认”消息只是 reply execute 的消息信息。因此,它将带有相同的名称(此处省略)。
  • 在执行规范的版本中,绘图工具不允许结束 execution specificationssend events 相吻合的reply-messages ,这本来是正确的。
  • alt 的守卫示例和 break片段(摘录):
    with guards
    sequencediagram.org/Item Executor (with Execution Specifications and guards)

    关于uml - 在序列图中转到?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54550717/

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