Sequence Diagram Tutorial

A sequence diagram describes an interaction among a set of objects participated in a collaboration (or scenario), arranged in a chronological order; it shows the objects participating in the interaction by their "lifelines" and the messages that they send to each other.

Sequence Diagram Example: ATM

What is a Sequence Diagram in UML?

UML Sequence diagrams are interaction diagrams that detail how operations are carried out. As sequence diagrams can be used to capture the interaction between objects in the context of a collaboration, one of the primary uses of sequence diagrams is in the transition from requirements expressed as use cases to the next and more formal level of refinement. Use cases are often refined into one or more sequence diagrams.

Sequence diagrams are time focus and they show the order of the interaction visually by using the vertical axis of the diagram to represent time what messages are sent and when.

Sequence Diagrams captures interaction in different level of granularity:

  1. high-level interactions between user of the system and the system, between the system and other systems, or between subsystems (sometimes known as system sequence diagrams)
  2. the interaction that takes place in a collaboration that either realizes a use case or an operation (instance diagrams or generic diagrams)
  3. Represent objects interact in (Model, View / Controller) MVC pattern of software framework

Try it!

Finding an online Sequence Diagram tool? Just click the Draw button below to create your Sequence Diagram online. Visual Paradigm Online is free* and intuitive. You can also go through this Sequence Diagram tutorial to learn about Sequence Diagram before you get started.

Draw Now

Sequence Diagram Notations

Lifeline

A lifeline represents an individual participant in the Interaction.

UML Sequence Diagram

Actor

An Actor a type of role played by an entity that interacts with the subject (e.g., by exchanging signals and data). An actor can also be an external to the subject (i.e., in the sense that an instance of an actor is not a part of the instance of its corresponding subject). They typically represent roles played by human users, external hardware, or other subjects.

UML Sequence Diagram: Actor example

Note That:

  1. An actor does not necessarily represent a specific physical entity but merely a particular role of some entity
  2. A person may play the role of several different actors and, conversely, a given actor may be played by multiple different person.

Activation

An activation is represented by a thin rectangle on a lifeline) represents the period during which an element is performing an operation. The top and the bottom of the of the rectangle are aligned with the initiation and the completion time respectively

UML Sequence Diagram: Activation example

Messages

Call Message

A call message defines a particular communication between lifelines of an interaction, which represents an invocation of operation of target lifeline.

UML Sequence Diagram: Call message example

Return Message

A return message defines a particular communication between lifelines of an interaction, which represents the pass of information back to the caller of a corresponded former message.

UML Sequence Diagram: Return message example

Self Message

A self message defines a particular communication between lifelines of an interaction, which represents the invocation of message of the same lifeline.

UML Sequence Diagram: Self message example

Recursive Message

A recursive message defines a particular communication between lifelines of an interaction, which represents the invocation of message of the same lifeline. It's target points to an activation on top of the activation where the message was invoked from.

UML Sequence Diagram: Recursive message example

Create Message

A create message defines a particular communication between lifelines of an interaction, which represents the instantiation of (target) lifeline.

UML Sequence Diagram: Create message example

Destroy Message

A destroy message defines a particular communication between lifelines of an interaction, which represents the request of destroying the lifecycle of target lifeline.

UML Sequence Diagram: Destroy message example

Duration Message

A duration message defines a particular communication between lifelines of an interaction, which shows the distance between two time instants for a message invocation.

UML Sequence Diagram: Duration message example

Note

A note (comment) gives the ability to attach various remarks to elements. A comment carries no semantic force, but may contain information that is useful to a modeler.

UML Sequence Diagram: Note example

When to Draw Sequence Diagram?

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

How to Draw a Sequence Diagram?

  1. Identify a set of objects that will participate in the general collaboration (or use case scenario)
    1. If you derive the sequence diagram based on a scenario of a use case, select the normal scenarios first
    2. You should know the primary actor(s) who activates the use case
  2. Consider the first point of the scenario (or if you get it from the first point of the flow of event of a use case)
  3. Consider what the system need to be done in order to response to the actor, when the actor send the message to the system
    1. What the system need to be handled before the return message response back from the system?
    2. E.g. A customer inserted an ATM card to the machine, the system will display "input pin number" in the normal scenario, right?
    3. Guess, what will to be handled inside the ADM by a set of objects at the "back" of the system? Something like, read and verify the ATM card (card reader), read the card information of the card holder (by the bank) and ask for the pin, or, return "invalid card type, insert another card", and etc.
    4. By this way, you will identify the candidate objects and operations of the target application for that particular scenario and you can also use these information as a basis to derive the class diagram incrementally.
  4. Repeat each of the point of the scenario (or flow of event) and until you complete all the points in the scenario.

You can also:

  1. Draw a set of corresponding sequence diagrams for the exception or alternative scenarios.

Sequence Diagram Examples

The sequence diagram example below shows the interactions between a user and a ticket booking system in booking a seat. It consists of mainly four parts: The actor, which is the user, the boundary object ‘interface', the controller object ‘mainController' and two entity objects routes and route.

Sequence Diagram Example - Book a seat

The sequence diagram example below shows a patient admission process. It shows the use of timing and duration constraint.

Sequence Diagram Example - Hospital bed allocation

The sequence diagram example shows how recursive message can be used in interaction modeling.

Sequence Diagram Example: Object creation and deletion

Want to draw a Sequence Diagram?

You've learned what a Sequence Diagram is and how to draw a Sequence Diagram step-by-step. It's time to get your hands dirty by drawing a Sequence Diagram of your own. Draw UML diagrams free* with Visual Paradigm Online. It's easy-to-use, intuitive.

Draw Now

* The Express edition supports free usage of Visual Paradigm Online for non-commercial use only.