Hi, my name is Angie and I'll be teaching you about UML sequence diagrams We'll start by explaining what a sequence diagram is and what it's used for and then we'll create an example of our own in This tutorial we assume you have a basic understanding of UML If you don't click the link in the corner to watch our other UML videos and learn more Sequence diagrams are a type of UML diagram that show how objects in a system or classes within code interact with each other Particularly these diagrams show interactions in the order. They take place in other words, they show the sequence of events They're primarily used by developers and business professionals to document processes or understand the requirements of a new program Now before we get started, let's talk about how we're going to make our example You could draw a sequence diagram with a pen and paper but a diagramming application is going to make things much easier Today I'm using the diagramming software Lucidchart. If you'd like to follow along, click the link in the corner to access Lucidchart's website, enter your email address and you'll have a free lucid chart account in just a few seconds.
It's easy to use and you can follow along with me as we build a sequence diagram. First we need a topic for our example. Let's diagram the interaction that happens at an ATM.
The first step is to think of the parts that make up whatever your topic is. If you're diagramming a system, that would mean all the parts of that system. If you're diagramming code, that would mean all of the classes that make up the program.
So in our case, what are the parts involved in an ATM transaction? A person goes to an ATM to get money. The ATM communicates with a bank server and that person's bank account is then accessed.
The ATM bank server and bank account are all a part of the ATM system. These three items are our objects. The person on the other hand is external to the system Therefore they're an actor actors are always outside the scope of the system in a sequence diagram Actors are represented by stick figures and objects are represented by rectangles So first, we'll drag out an actor and place them here on the left.
This represents the person trying to get money Then we'll add our objects alongside it We'll start by naming this object ATM because the person first interacts with the ATM then bank server and Finally bank account You want the objects to be placed in sequential order from left to right? Next we'll need to add a lifelines Lifelines are the vertical dashed lines that show the existence of an object or actor over time? Moving down the Lifeline means that more time is passing.
So we'll drag out a lifeline for the actor and for each of our objects Now that we have our base chart laid out we can start to diagram the interaction between our actor and our objects To start think of all the steps that happen when you go to get cash at an ATM The first thing you'll need to do when you get to an ATM is insert your card. That will be our first message messages show the information being sent between objects sequence diagrams show the order of interactions or Sequences and they do this by moving down the life line with each message So we'll start with the first one at the top drag out a line that connects the actor life line to the ATM life line Now give it a label insert card Next the ATM checks with the bank server to make sure it's a valid card. We'll drag out a line and place it between ATM and Bank server just below the previous message line.
Well label this one verify cart The server verifies the card and sends a message back to the ATM when an object sends a message back This is called a return or reply message and they're always represented by a dashed line Return lines often move from right to left. That isn't always the case as we'll see in a minute So we'll drag out another line and connect it from the server life line to the ATM life line We also need to change the line from solid to dashed again The dashed line represents a return message or a message from the receiving object back to the requesting object We'll label this message as card Okay, after the card has been validated the ATM will ask for a pin So we'll draw a line from the ATM to the actor and label it request pin Because this message isn't replying to an earlier message and is requesting information Rather than responding. This message is not a reply message and will be denoted by a solid line So what happens when the card is invalid like when an inserted card is expired?
This is when an alternative frame is used an alternative frame symbolizes a choice between two or more message sequences These choices are usually mutually exclusive. So in this case the conditions are if the card is valid or if it's not We'll drag out one of these boxes and place it around the two messages. We just created The upper portion of the box will be labeled if card is valid and the lower portion will say else this says that if the card is valid tell the ATM and the ATM will request a pin if The card is not valid the server will tell the ATM and the ATM will eject the card Will make two more messages that show the alternate interaction labeling them card invalid and eject card After the ATM has determined the card to be valid and requested a PIN the user will input their PIN Since the ATM requested the PIN and this is the user's response to that request.
This message will be a return message So we'll make a dashed line from the actor to the ATM and label it PIN entered The ATM will then ask the server if the pin is correct. We'll draw a line to represent that interaction and label it verify PIN Now we have the same situation as before where we'll need to use an alternative frame First we'll create what happens if the pin is valid the server will tell the ATM The pin is valid and the ATM will ask the user how much cash they want to withdraw So we'll drag out our alternative frame and place it around the two new messages labeling the top portion if pin is valid Next we'll add the alternative messages the server will tell the ATM. The pin is invalid and the ATM will eject the card We'll continue to map out the rest of the interaction by creating messages and return messages until the Transaction is complete and the actor has received their money The user will input an amount and the ATM will start a transaction with the server the server then asks the bank account if there are sufficient funds to cover the Transaction if funds are sufficient the server will withdraw the amount until the ATM to dispense the cash If the funds are not sufficient won't want the transaction will be unsuccessful Finally the card will be ejected after the cash is dispensed or the transaction was cancelled With our interaction complete now we can add activation boxes Activation boxes show when and how long an object is performing a process This shows us at a glance when objects are active and when they are idle So we'll drag one out place it on the ATM lifeline and fit the box around the first and last message on the Lifeline We'll do the same for bank server and bank account since as we discussed before Actors are external objects.
They don't need an activation box Now we can easily see that bank account is much less active than the rest of the objects in this sequence While this example is fairly simple sequence diagrams can get even more complex for example If you're diagramming code The objects might be labeled as the names of classes and the messages might be the methods and functions Used in the code. It all depends on what you need to diagram and how complex you need it to be Thanks for watching this tutorial on sequence diagrams.