Messages

A message is a model element that specifies a communication between classifier roles and usually indicates that an activity will follow. The types of communications that messages model include calls to operations, signals to classifier roles, the creation of classifier roles, and the destruction of classifier roles. The receipt of a message is an instance of an event.

For example, in the observer pattern, the instance that is the subject sends an "Update" message to instances that are observing it. You can illustrate this behavior by adding "Subject" and "Observer" classifier roles and then adding an "Update" message between them.

Shape

A message appears as a line with an arrow. The direction of the arrow indicates the direction in which the message is sent. In a sequence diagram, messages usually connect two classifier role lifelines.

Message shapes can be adorned with names and sequence numbers.

Types of Messages

Different types of messages can be used to model different flows of control.

Type Shape Description
Procedure Call or Nested Flow of Control Models either a call to an operation or a call to a nested flow of control. When calling a nested flow of control, the system waits for the nested flow of control to complete before continuing with the outer flow.
Asynchronous Flow of Control Models an asynchronous message between two objects. The source object sends the message and immediately continues with the next step.
Return From a Procedure Call Models a return from a call to a procedure. This type of message can be omitted from diagrams because it is assumed that every call has a return.

Using Messages

Messages can appear in a sequence diagram to represent the communications exchanged between classifier roles during dynamic interactions.

Note Both messages and stimuli are supported. Stimuli are added to collaboration instances, and messages are added to collaborations. For details about stimuli, see Stimuli.

The messages in a model are usually contained in collaborations and usually appear in sequence diagrams.

Naming Conventions

Messages can be identified by a name or operation signature.

Type Example Description
Name // Get the Password A name identifies only the name of the message. Simple names are often used in diagrams developed during analysis because the messages are identified by their responsibilities and not operations. One convention uses double slashes (//) to indicate that the stimulus name is not associated with an operation.
Signature getPassword(String) When an operation is assigned to a message, you can display the operation signature to identify the name of the operation and its parameters. Signatures are often used in diagrams developed during design because the provide the detail that developers need when they code the design.

Related Topics

Classifier Roles | Lifelines |UML Sequence Diagrams