Haru
Haru

Reputation: 91

Self Message vs Return Message in Sequence Diagram

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?

Upvotes: 4

Views: 3991

Answers (2)

Axel Scheithauer
Axel Scheithauer

Reputation: 3625

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.

Upvotes: 1

Christophe
Christophe

Reputation: 73406

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.

Upvotes: 3

Related Questions