Rules, which object‘s method to write on arrows in UML sequence diagrams?

Viewed 336

Are there any rules, if methods written on arrows in uml sequence diagram (related to say java code) are the methods of the object, where the arrow comes from or where it goes to? Does this depend on the sort of arrow or its directions or are there no exact rules for that at all? Thanks a lot.

2 Answers

Yes, there are rules. You specifically ask about "methods written on arrows", so I will stick to "methods" (called "operations" in UML terms), although it is also possible to mention signals.

For methods, there are two arrow types:

  1. Request arrow: An arrow from caller to callee, with a solid line and a filled arrowhead (or an open arrowhead if it is an asynchronous call).
  2. Reply arrow: An arrow from callee to caller, at the point where the method returns, with a dashed line and an open arrowhead.

In case of a request arrow, the label of the arrow shows the name of one of the methods of the target of the arrow. In case of a reply arrow, the label shows one of the methods of the source of the arrow.

You may choose to only draw request arrows and forget about reply arrows.

The syntax of the labels of these arrows is specified in section 17.4.4 of the UML specification.

The label of a request arrow has the following syntax:

syntax of request

The message-name is the name of the method that is called. Example:

example of request

If you wish, you may omit the parameters and just write requestUniqueId.

The label of a reply arrow has the following syntax:

syntax of reply

The message-name is the name of the method that just ended. Example:

example of reply

You may also draw reply arrows without labels, if you don't want to show the returned values in your diagram.

In short

Yes the object's "method" on the arrow refers to the target's "method".

Some more explanations

The arrows in a sequence diagram represent messages.

A message is either an operation or a signal. And depending on what it is, it must be the name of either an operation or a signal:

  • an operation is in UML jargon what many programming languages call a method. The message semantics are in this case:

    If the messageSort is either synchCall or asynchCall, then the Message represents the synchronous or asynchronous call to and start of execution of the Operation.
    If the messageSort is reply, then the Message represents the return from a synchronous call to the Operation.

    So it is the sender that calls an operation of the target.

  • a signal:

    is a specification of a kind of communication between objects in which a reaction is asynchronously triggered in the receiver without a reply.

Signals are a special beast that would require a lot more explanations that are not relevant for your questions. I mention it only to say that it is not necessarily only about "methods". But the semantics are likewise: the receiver at the end of the arrow needs to process it.

Edit: Reply messages (dashed arrows that do not create an object) return to the caller and have a slightly different rule. Very often, they are left without any label as their identity is obvious, or they do not match an operation signature and just indicate a result. However, if they indicate an operation name, it should be the name of the message that initiated the "call" (which means, in this special case, the name of the operation that was called on the source and returns). Thanks @www.admiraalit.nl to highlight the need to explain my shortcut.

Related