Sequence Diagram

What is a Sequence Diagram?[1]

A sequence diagram is a Unified Modeling Language (UML) diagram that illustrates the sequence of messages between objects in an interaction. A sequence diagram consists of a group of objects that are represented by lifelines and the messages that they exchange over time during the interaction. A sequence diagram shows the sequence of messages passed between objects. Sequence diagrams can also show the control structures between objects. For example, lifelines in a sequence diagram for a banking scenario can represent a customer, bank teller, or bank manager. The communication between the customer, teller, and manager is represented by messages passed between them. The sequence diagram shows the objects and the messages between the objects.

Elements of Sequence Diagram[2]

A sequence diagram shows, as parallel vertical lines (lifelines), different processes or objects that live simultaneously, and, as horizontal arrows, the messages exchanged between them, in the order in which they occur. This allows the specification of simple runtime scenarios in a graphical manner. A system sequence diagram should specify and show the following:

  • External actors
  • Messages (methods) invoked by these actors
  • Return values (if any) associated with previous messages
  • Indication of any loops or iteration area

Purpose of Sequence Diagram[3]

  • Model high-level interaction between active objects in a system
  • Model the interaction between object instances within a collaboration that realizes a use case
  • Model the interaction between objects within a collaboration that realizes an operation
  • Either model generic interactions (showing all possible paths through the interaction) or specific instances of an interaction (showing just one path through the interaction)

Use cases for sequence diagrams[4]

The following scenarios are ideal for using a sequence diagram:

  • Usage scenario: A usage scenario is a diagram of how your system could potentially be used. It's a great way to make sure that you have worked through the logic of every usage scenario for the system.
  • Method logic: Just as you might use a UML sequence diagram to explore the logic of a use case, you can use it to explore the logic of any function, procedure, or complex process.
  • Service logic: If you consider a service to be a high-level method used by different clients, a sequence diagram is an ideal way to map that out.

Benefits and Drawbacks of a Sequence Diagram[5]

Benefits of a Sequence Diagram

  • Sequence diagrams are used to explore any real application or system.
  • Sequence diagrams are used to represent message flow from one object to another object.
  • Sequence diagrams are easier to maintain.
  • Sequence diagrams are easier to generate.
  • Sequence diagrams can be easily updated according to the changes within a system.
  • Sequence diagram allows forward as well as reverse engineering.

Drawbacks of a sequence diagram

  • Sequence diagrams can become complex when too many lifelines are involved in the system.
  • If the order of the message sequence is changed, then incorrect results are produced.
  • Each sequence needs to be represented using different message notations, which can be a little complex.
  • The type of message decides the type of sequence inside the diagram.

See Also

Unified Modeling Language (UML)