自我消息与返回消息序列图

发布于 2025-01-18 14:34:08 字数 248 浏览 2 评论 0原文

自我消息和回复消息有什么区别。 这里有 2 个示例:

自我消息:

自我消息

返回消息:

return message

哪个示例是正确的?

What the difference between a self message and a return message.
Here 2 examples:

Self Message:

self message

Return Message:

return message

Which example is correct?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

那一片橙海, 2025-01-25 14:34:08

当生命线是对象时

自我消息与其他消息一样,只是它有一个特殊的收件人。通常,您可以通过让类的一个操作调用同一对象的另一个操作来实现第一个示例。伪代码:

class WebInterface {
  …
  public void showList() {
     …
     display();
     …
  }
  public void display() {
     …
  }
  …
}

返回消息将结果提供给调用者。通常,对于通过操作调用实现的同步消息,它将对应于值的返回。伪代码:

class WebInterface {
  …
  public Display showList() {
     Display display;
     …
     return display;
  }
  …
}

当涉及参与者时

在您的示例中,您在序列图中使用了参与者。原则上,参与者位于系统外部,而序列图显示系统内部的消息交换。尽管这种做法很流行,但它是含糊不清的,因为没有定义用于与人类交换消息的语义。

在这个特定的上下文中,它具有更非正式的含义:

  • 两个例子都表明
    子系统与用户的交互,而不是对象之间的正式消息交换。在这两种情况下,用户都会激活一些按钮或菜单,告诉 Web 界面应该显示一个列表。
  • 在第一个示例中,在 Web 界面中显式调用 display 操作表明将进行一些显示。我们隐含理解用户会得到一些视觉反馈。
  • 在第二个示例中,返回消息以显示结果的形式*明确向用户建议反馈。

When lifelines are objects

A self-message is a message like any other, except that it has a special addressee. Typically you would implement the first example by having one operation of a class call another operation of the same object. Pseudocode:

class WebInterface {
  …
  public void showList() {
     …
     display();
     …
  }
  public void display() {
     …
  }
  …
}

A return message provides a result back to the caller. Typically for a synchronous message implemented with a call of an operation, it would correspond to the return of the value. Pseudocode:

class WebInterface {
  …
  public Display showList() {
     Display display;
     …
     return display;
  }
  …
}

When an actor is involved

In your examples, you use an actor in the sequence diagram. In principle, an actor is external to the system whereas a sequence diagram shows message exchanges within the system. Although this practice is popular, it is ambiguous, because no semantics are defined for exchanging messages with a human being.

In this particular context it’s a more informal meaning :

  • Both examples suggest
    interactions of a subsystem with a user instead of formal message exchange between objects. In both cases, the user would activate some button or menu that would tell the web interface that it should show a list.
  • In the first example, the explicit call of a display operation within the web interface suggests that some displaying would take place. We implicitly understand that the user would get some visual feedback.
  • In the second example, the return message suggests *explicitly a feedback to the user, in form of a displayed result.
风吹短裙飘 2025-01-25 14:34:08

自我消息是给自我的消息,回复消息(您称其为“返回消息”)是向先前的同步消息发送者的消息。它与此同步消息有关,因此不能具有自己的名称(“显示”)。即使您在第二种情况下没有对其进行建模,也总是假定它在那里。它可以定义一个返回值,但是将在结肠后显示。因此,它的正确标签是可以

showing list:"some text"

遗漏消息名称,但是当需要回返回值时,结肠应始终在那里。

请参阅UML规范:

第17.4.4.1节消息

使用回复标签来回复
消息。它具有以下形式:< revall-message-label> :: =
[< tissment-target> '=']< message-name> ['('
[< output-argument-list>]')'] [':'< value-规范>]

@christophe在他的回答中指出,涉及人类信息的语义尚未明确定义。同步消息尤其如此。我认为,在现实生活中,它们根本没有意义。发送同步消息后,发件人应该等待回复消息。我认为不可能强迫人类这样做。因此,我建议在此处使用异步消息。例如,向自我的显示消息可能会导致发送给客户的异步消息。

The self message is a message to self, and the reply message (you called it "return message") is a message to the sender of the preceeding synchroneous message. It is tied to this synchroneous message and as such cannot have an own name ("display"). It is always assumed to be there, even if you didn't model it in the second case. It can define a return value, but it would be shown after a colon. So the correct label on it would be

showing list:"some text"

It is OK to leave out the message name, but the colon should always be there when a return value is needed.

See the UML specification:

section 17.4.4.1 Message

A reply-message-label is used for reply
Messages. It has the following form: <reply-message-label> ::=
[<assignment-target> ‘=’] <message-name> [‘(’
[<output-argument-list>] ‘)’] [‘:’ <value-specification>]

As @Christophe has pointed out in his answer, the semantics of messages involving humans is not clearly defined. This is especially true for synchroneous messages. I would argue, that they don't make sense at all in real life situations. After sending a synchroneous message, the sender is supposed to wait for the reply message. I think it is not possible to force a human to do that. Therefore, I recommend to use asynchroneous messages here. For example, the display message to self could lead to an asynchroneous message being sent to the customer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文