The sequence diagram is part of UML’s behavioral suite of diagrams, used to show interaction between tow of more object in the context of time as they occur.
The sequence diagrams typically show the logical view of the system and interactions with it in form of events in one or more scenarios, therefore sometimes sequence diagram is also called event diagram.
“A sequence diagram is a dynamic model that shows the explicit sequence of messages that are passed between objects in a defined interaction. Because sequence diagrams emphasize the time-based ordering of the activity that takes place among a set of objects, they are very helpful for understanding real-time specifications and complex use cases.” Dennis, A., Wixom, B. H., & Tegarden, D. P. (2015).
Main building blocks of sequence diagrams are actors, lifeline, objects, guard condition, execution occurrence and message. Lifeline represents each participating actor, its interactions during over the time. It is represented by the box with vertical dotted line such as following.
An object represents the other parts of system where messages are sent and received. An execution occurrence show sending or receiving of message in the context of time frame.
The message represents an event of sequence diagram in the form of request or response. It is denoted by arrow going left to right for request of event and from right to left for response of the event or action such as following.
Message can be either synchronous asynchronous. The synchronous message is denoted by solid head arrow, and asynchronous is represented by a regular arrow sign.
Finally, the guard condition ensures the constraint or condition needs to be satisfied in order to send the message to system.
Steps used to create a sequence diagram
The sequence diagrams are a greater way to model usage behavior of the system in terms of timeline interactions of actors. The sequence diagram can be generic to show the general behaviors of the system, or it can be specific to instance. Single scenario-based sequence diagrams are recommended way to model in real-world software systems.
Let’s take an example of patient appointment system, where patient comes in for appointment scheduling, the logical flow of the interactions would be request appointment to receptionist. The receptionist would check the system to see if patient is new or exiting.
If in the case of new patient, he is asked to fill paperwork, and in the case of existing patient, receptionist check patent system to see if he or she has any unpaid bills and then schedule appointment based on availed time slots with physicians. If we were to draw a sequence diagram what would be the flow?
First, we will extract the actors in the system which is patient, receptionist, patient system, unpaid-bills and appointment module.
All the actors in this image are drawing with their lifeline, and the arrows show the messages flowing through the system.
The patient and receptionist are actors in the system, Patient, Unpaid-Bill and Appointment also represents objects in the system. Lookup patient is guard condition to check if patient already exists, based on what different messages are sent within the system.
The execution timeline is drawn as vertical boxes. The messages are flowing through the system in forward and back depending upon the action and response.