Sequence diagrams are a type of UML diagram that shows interactions between objects in sequential order. Developers and business analysts primarily use them to understand the project and its requirements. It illustrates how different parts of a system interact with each other and in what order each interaction is executed.
Sequence diagrams show elements as they interact over time, and we place them according to object and time. The object is represented on the horizontal axis, and they are the elements that interact. Time is represented on the vertical axis, which is the progress in terms of time.
Note: The time axis does not represent the duration of the interaction but is about creating the sequence.
Elements of the sequence diagram include the following:
Lifeline Notation
Activation Bars
Message Arrows
Comment
The lifeline notation represents an instance or object that interacts with other objects in the system. They are shown as a labeled rectangle and dragged down horizontally by a dashed line to establish the existence of an object or actor during the process. More than one lifelines cannot overlap with each other. Here is how we make one:
A rectangle along its lifeline represents an activation bar. It indicates that an object is active during the interaction process between objects. The length of the rectangle represents the duration of the interaction. Here is a visual representation of an activation bar:
Messages between lifelines indicate communication between objects and are made in sequential order. We do this by moving down the lifeline with each message. The description of the message is written on the arrow. The arrows can go in any direction, such as right to left, left to right, or back to the message itself.
We have different types of messages that are represented by different arrowheads:
Synchronous message: This is a regular message sent to the receiver, which the receiver processes before continuing with the other messages along the line. We represent this by a solid line with a filled arrowhead.
Asynchronous message: This is just like synchronous, except it has no reply. The interaction continues regardless of whether the first object has processed the previous message. We show this by a solid arrow with an open arrowhead.
Reply message: This represents the pass of information back to the caller of the former message. It is shown by a dotted line with an open arrowhead.
Self Message: The message that the object needs to send to itself. It is indicated with an arrow that starts and ends at the same lifeline.
Create Message: This is used to initiate a new object and is usually used when a message requires the creation of an object. It is drawn as a dotted line with an open arrowhead and the <<create>>
word labeled on it.
Delete message: We use this to destroy an object, and it is shown by an arrow. We show this by drawing with an X at the end.
Before drawing a sequence diagram, we first need to know which interactions will we include with a detailed description of each use case. Let us consider a login system as an example. We have the following things:
We first identify the objects included in the system
User
Login screen
Validation
User credential database or server
Then we list down the steps involved in the execution of the system in chronological order:
The user clicks on the login button.
The page is redirected to the login screen.
The user enters their credentials.
The user's details are checked with the existing database.
When the user details match, a success message will appear on the user's screen.
Free Resources