Sequence Diagram - Step by Step Guide with Example

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcomes to master2 teach step by step guide in this video we are going to learn what is sequence diagram what are the different parts of sequence diagram we will go through one by one how to draw a sequence diagram we'll see step by step we will also see an example drawing sequence diagram with case study I will try my best to explain step by step if you haven't subscribed to our channel please click on the subscribe button and subscribe to our YouTube channel ok let's start what is sequence diagram before restarting I would like to make clear that the sequence diagram is also called as an even diagram or even scenario the UML diagram which shows an interaction between object arranged in the time sequence is a sequence diagram sequence diagram listed how the different part of system interact with each other to carry out a function and the order in which the interaction occur when a particular use case is executed as I have already mention in my previous video tutorial of communication diagram sequence diagram and the communication diagram are the type of interaction diagram where it shows how objects of classes communicate by sending and receiving messages also I have already mentioned that these two diagrams communication and sequence diagram are isomorphic which means you can convert one diagram into another diagram so far we have gone through how to draw use case diagram and how do we write high-level and expanded use case description in the previous video tutorial if you haven't gone through it please find the link above or in the description of this video and go through it before you start sequence diagram after the expanded use case description of the major use cases we can start either the communication diagram or sequence diagram so that you should know what is expanded each case description and how to write expanded each case description is a two-way interaction steps written between the actor and the system how that particular use case will execute we have already drawn the communication diagram in the previous video now let's draw the sequence diagram the sequence diagram is an interaction diagram that shows details on how operations are carried out like what masses are sent and when it can be drawn at different levels of details and to meet different proposes at several stages in the development lifecycle typically used to represent the detailed object interaction that occurs for one use case or for one operation we all know that objects of the classes communicate by sending and receiving messages let me show you an example how objects of the classes communicate by sending and receiving messages in coding here is class A with method name as method A which will preform certain tasks another Class B with method name as method B which will also perform certain tasks now another Class C which is the main class or controller class here new object a of class A is created also new object b of class B is credited a dot method A where C says to A that method A should be executed answer is equal to b dot method B C says to B that method B should be executed and B returns the results to C which is store in answer variable in this way object of the class is communicated by sending and receiving messages I hope you are more clear about how do the object communicate and showing this interaction of the objects message sending and receiving stepwise arrange in time sequence is a sequence diagram a sequence diagram is structured in such of way that it represents a time line that begins at the top and descends gradually to mark the sequence of interaction each object has a column and the messages exchanged between them are represented with arrows let's go through each and every parts of sequence diagram step by step number one dimension a sequence diagram is drawn in two dimension horizontal and vertical object dimension the horizontal axis shows the elements or objects that are involved in the interaction are listed from left to right according to when they take part in the message sequence they can be appear in any order in the horizontal axis time dimension the vertical axis in the sequence diagram shows the time from top to down note that our sequence diagram is all about the ordering not duration so that while drawing sequence diagrams we have to careful on timing and ordering but we don't mention the duration of time on it actor anyone who used to perform a certain function in the system is actor actor maybe someone or something that can be a person an organisation another system machine or any external device so who or what is going to use our system is actors like customer staff admin bank student teacher etcetera the actor is representing by the human stick image as same as in use case and communication diagram lifeline a lifeline represents an individual participant in the interaction a lifeline is shown using a symbol that consists of a rectangle forming its head followed by a particle line which may be dashes that represents a lifetime of the participant they represents that different objects or parts that interact with each other in the system during the sequence the standard in UML for naming a lifeline follows the following format instance name : class name it represents the passes of time as it extends downward as the object is destroyed the lifeline ends there no two lifeline notations should be overlap each other a lifeline notation with an actor element symbol is used when the particular sequence diagram is owned by the use case activations a thin rectangle box on a lifeline represents the time needed for an object to complete a talk simply we can define as the execution of an operation the top and the bottom of the rectangles are aligned with the initiations and the completion times respectively it reflects the time of execution so that the activation box become longer as the task is longer message a message defines a particular communication between life lines of an interaction which means showing how the objects interact with each other by sending and receiving messages the messages appears in sequential order in the lifeline we represent messages using arrows we can further classify the messages as follows synchronous messages synchronous messages represented by a solid line with a solid Arrowhead this symbol is used when a sender must wait for a response to a message before it continues the sender wait until the receiver had completed the processing of the messages the caller continues only when it knows that the receiver has processed the previous messages i.e it receives a reply messages the diagram should show the both the call and reply to messages asynchronous messages an asynchronous message doesn't wait for the response from the receiver before the sender continue the interaction moves forward irrespective of the receiver processing the previous message or not we use a line arrow to represent an asynchronous message and only the call should be included in the diagram return message a return message is used to indicate that the message receiver is done processing the message and is returning control over to the massage caller note that returning messages are optional notations and only triggered by the synchronous messages you can avoid cluttering up your diagram by minimizing the use of return messages since the return values can be specified in the initial message arrow itself create messes an object can be created at any times of excitation of the process to represent the new object created in the process of execution create a message is used it is represented by a dashed line with a line Arrowhead and label with word create on it to specify that it is the crate message symbol reflexive messages sometimes an object needs to communicate with the same class methods that is when an object sends a message to itself it is called the reflexive message it is indicated with a message Arrowhead that starts and ends at the same lifeline as shown in the diagram object destruction as soon as the object does not need anymore in the further process object destruction is called which is deleting the object object destruction represents the request of destroying the lifecycle of the target lifeline which is shown Cross lines and there will not further lifeline symbols mean dotted line it destroys the occurrence of the object in the system comment a comment or a note can be used to reflect the various remarks to the elements a comment carries no semantic force but may contain information that is useful to the modular the common object is our rectangle with a folded over corner as shown in the diagram the comment can be linked with a related object with a dashed line now let's move further focus of control the focus of control indicates times during activation when processing is taking place within that object the focus of control is also known as an execution occurrence it represents the period during which an element is performing an operation the top and the bottom of the rectangle are aligned with the initiations and the completion time respectively the focus of control can be shown as follow the white gap in the activation reflex the waiting time and shaded with black reflect the execution time control object the control object is to manage the collaboration of the objects which gives effect to the use case process the name of the controller object is the same name as the use case name like control object for the use case enroll student is : enrollstudent don't forget to underline the text as well boundary object most use cases imply at least one boundary object that managed the dialogues between is the actor and the system boundary object will also have the same name as the use case name with the additional of UI at last like :enroll student UI this object is for the user interface control object and boundary object are similar as the communication diagram now let's learn further more advanced in the sequence diagram guards when modeling object interaction there may be the certain condition that must be met for a message to be sent to the object to model conditions like if condition in programming we use guard in sequence diagram guards play an important role in letting software developer know the constraints attached to the system's or a particular process for example in order to withdraw cash from the bank the account balance should be greater than zero so balance greater than zero is a condition that must be made for this message to be called which can be shown in the sequence diagram like this alternative in Guards we represents the if condition in the diagram whereas alternative in sequence diagram symbolize a choice between two or more messages sequence to model a choice of the message with a condition like if-else condition in programming we use an alternative the alternative fragment is represented by a large rectangle or a frame it is specified by mentioning alt inside the frame name box as shown in the diagram to represent alternatives use the label rectangle shape with dashes line inside as shown in the figure only the one whose condition is true will execute optional optional is similar to guards where the fragments execute only if the supplied condition is true guards are used only for a single message whereas optional is used to model fragments of the process as shown in the figure it is represented by a large rectangle or a frame where opt is labeled inside the box similar to the alternative in the alternative there are a if else condition whereas in optional there is only if condition same as guards parallel in parallel these fragments is run in parallel if the condition is match each fragment or the massage will execute parallel the notation of parallel is similar to the combination of optional and alternatives where there will be the only one condition as optional and multiple messages or fragments as alternative it is also represented by the large rectangle where Par is label inside the box as shown in figure loops the fragments may execute multiple times which may be need to model in the diagram sequence diagram has been improved with the addition of the loop combinations fragments loops fragments is used to represent a repetitive sequence and it is very similar in appearance to the optional for loops draw a frame and inside the frame's name box label with text loop inside the frame context area the loop guard or condition is placed towards the top left corner as shown in figure the loop sequence of the messages is placed in the reminder of the frames context area in the loops there can be two special condition tested against in addition through the standard boolean test the special condition our minimum iterations written as min int is equal to the number like min int is equal to 1 and the maximum iteration written as max int is equal to number like max int is equal to ten with a minimum iteration guard the loop must execute at least the number of time indicated whereas the maximum iteration condition the number of loop activations cannot exceed the number sequence diagram the entire sequence diagram is surrounded by the box or frame and inside the frame name label with text SD : process name beside this there are other notation like Negative the fragments shows an invalid interaction another type is reference reference refers to an interaction defined on the another diagram the frame is drawn to cover the lifeline involved in the interactions you can define parameters and a return value so using this all elements we can draw the sequence diagram how to draw sequence diagram now let's move to learn how to draw sequence diagram as I have already mention you before the sequence and the collaboration diagrams is derived from the high label and expanded use case description of the use case let's take the same use case example which we have drawn in the previous use case tutorial it's a college student record system application where a student can enroll online in the college themselves from home the high level and expanded use case description of the use case enroll students are as we know in expanded we write interactive description between the actor and the system number 1 the new students provide personal details for enrollment number 2 system response and shows available course as options number 3 choose the best course among the available course number 4 the system provides a confirmation message of enrollment to each student so the first step is go through the use case description and list the domain classes how to find domain classes I have already explained in details regarding how to find domain classes in previous video if you haven't gone through it please find the link just top right corner of this video or in the description below the major class which needs to define while executing the use case are the domain classes now first of all find the nouns from the description and list those which are importance to the processing if the system has to process data about the type of person or the object name then this is probably a relevant class of objects like student data needs to store course options should be provided and chosen courses data need to process the possible classes of the use-case enroll student are number one student number two course and number three enrollment after successfully identifying all domain classes we need another two classes to manage the collaboration of objects which gives effects to the use case process it's a control object to manage the screen interactions father use case it's a boundary object so the first step of drawing sequence diagram is finding the domain classes whereas the second step is drawing controller object lifeline add a control object in a diagram note that the name of the controller object is the same as the use case name here we are taking an example of entoll student use case so the controller object name must be : enroll student the next step which is the third step is drawing boundary object lifeline boundary objects will also have the same name as the use case name with the addition of UI at last like : enroll student UI the object is for the user interaction now the fourth step where we draw the actor lifelines just beside the boundary object because actor interacts with the system interface actor notation is similar to the use case diagram which is represented by the human stick image and lifeline is drawn with thin rectangle box as shown in figure now moving forward to the fifth step which is adding messages to the diagram in time sequence from top to bottom we assume that the user interface was started up by the menu process then perhaps the first message might be displaying enroll form to the user in the boundary object lifeline the control object the boundary object and the actor are appearing simultaneously so that they are drawn in the same horizontal line the user or actor will fill out all the required information and send to the controller object by interacting with the boundary object which is shown in the sequence diagram as follow note that in sequence diagram the vertical flow represents the time flow so that the arrow of message passing and returning can't be drawn tilted upward position it can be drawn in straight position as well as tilted a little bit downward position because every lines of code execution and calling method take time once the user has entered all the information like name address etc the data might be sent to the controller object using the message record personal details I am following the camel casing naming convention here and there should not be any space between the letters as you can see at last we end with the parentheses it's a method name where we can show the passing arguments as well also remember that the messages are shown in the serial wise like at first display enrollment form method is executing and after that the actor field personal detail method is executing and after that record personal detail like this the activation box symbolizes the time it will take to perform that task there is not exact measurement of time as I have already mentioned you before it only reflects the time it will take to execute the process small box is for the small time whereas long box for more time to execute the process let's move forward the control object will create a new object of student class to store all the info provided by the students so the next step which can be number as sixth step drawing domain class object lifeline note that it is called by the create messes and draw the object lifeline in the same horizontal position where the object is created the sequence diagram show when the new object is created the control object will call the constructor automatically as soon as the new object student is created which can be shown as in figure while control object calls the constructor of the student class control object has to wait for finish executing and return message from the student object lifeline which can be shown in the figure like this it is called as the focus of control as soon as the control object get the return message it will create a new object for the enrollment similar to the student object we can show in figure as follow constructor of the enrollment class will auto call when new object is created by control object next step is control object needs to display the list of course available to student in the boundary object so controller object creates a new object of class course and call for the get course details here multiple courses have multiple information to display which means need to create multiple objects to store their respective information which we can show in loops in sequence diagram as shown in figure note that we mention * in the communication diagram for the iteration after control object get returned message from the course lifeline it passes to boundary object to display in the screen for students and student will choose the desired course and submit to control object from boundary object the control object stores the choosen course to the same student enrollment object at last place these diagrams in the frames with SD : enroll student label on it in this way we can draw the sequence diagram following step by step note that the sequence diagram depends on how the analyst chooses to allocate responsibilities between the objects and the chosen order of processing it would be possible to draw an entirely different sequence diagrams to the same task and if both sequence and collaboration diagram are prepared this should be consistent I hope you learn from this video tutorial if you have any questions or comments please make sure to leave a comment in the comment section below also please be sure to LIKE this video and subscribe to my channel if you haven't already thank you very much for watching check us out for more in IT tutorial and guide on website master2teach.com and we will see you again soon bye
Info
Channel: Master2Teach
Views: 15,650
Rating: 4.8151259 out of 5
Keywords: sequence Diagram, uml sequence diagram, sequence diagram tutorial, how to draw sequence diagram, sequence diagram in uml, sequence diagram example, how to make a sequence diagram, even diagram, event scenario, object communication, lifeline, activations, messages, synchronous message, asynchronous message, return message, create message, reflexive message, object destruction, focus of contorl, control object, boundary object, guards, alternative, optional, parallel, loops, reference
Id: _Mzi1rYtI5U
Channel Id: undefined
Length: 24min 21sec (1461 seconds)
Published: Tue Apr 14 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.