How to Draw UML Sequence Diagram?
March 16, 2016
When you want to model the structure of a system or an application, you can make use of class diagram. When you want to model the interaction between objects in runtime, with the sequence of method invocation, you can make use of sequence diagram. Class diagram and sequence diagram can be related with each other. While a class in class diagram represents a blueprint of data, a lifeline in sequence diagram represents an instance of such blueprint. In this tutorial, we will start from a simple class diagram, and make use of a sequence diagram to model the dynamic method invocation related to a controller class modeled in class diagram.
- Download Simple-Registration.vpp. You can also find this file at the bottom of this tutorial.
- Open the downloaded .vpp file in Visual Paradigm. To open a project, select Project > Open from the application toolbar.
- Open the class diagram Registration. Study the diagram content. We have three classes - RegistrationUI, RegistrationController and User.
- Now, we want to model the interaction between object instances of these classes in runtime. Since the controller class is responsible to control the registration process, add a sub-sequence diagram from it. Move the mouse pointer to RegistrationController. Click on the resource icon at the bottom right corner and select New Diagram... from the popup menu.
- In the New Diagram window, select Sequence Diagram and click Next. Keep the diagram name as provided and click OK to confirm.
- This creates an empty UML sequence diagram. Select Boundary LifeLine (B) from the diagram toolbar.
- Click on the diagram to create a boundary lifeline.
- Enter registrationUI as the name of lifelife and then press Enter to confirm.
- Right click on the lifeline and select Select Class > Select Class... from the popup menu.
- In the Select Class window, select the RegistrationUI class and then click OK to confirm.
After that, the lifeline will look like the following.
- Create a Control LifeLine registrationController : RegistrationController and an Entity LifeLine user : User. Don't forget to select the appropriate classes for them. The diagram will look like the following.
- Let's model the method invocations between lifelines. Move the mouse pointer over lifeline registrationUI.
- Press on the Resource Catalog resource and drag it out.
- Move to lifeline registrationController and release the mouse button.
- Select Message from Resource Catalog.
- This pops up a list of name that you can choose for the new sequence message. You can see that those are operation of classRegistrationController. Select createUser(name, password).
- Relate lifeline registrationController and user. We say that registrationController creates the user lifeline. Therefore, we need to relate them with a create message. Move the mouse pointer over the activation in lifeline registrationController.
- Press on the resource Resource Catalog and drag it out.
- Release the mouse button on the lifeline user.
- Select Create Message from Resource Catalog.
Create message is created. Your diagram should look like this:
- Create messages setName and setPassword from lifeline registrationController to user. Up to now, the diagram becomes:
- You can also specify the arguments of operations. Take the message createUser(name, password) as example. Right click on it and select Open Specification... from the popup menu.
- Edit the action type property by clicking on the button with dotted caption, next to Action type.
- In the Call Action Specification window, click Add > Text... to add an argument. In this example, click Add > Text... to add argument peter. Click Add > Text... again to add argument mypwd. Note that the two arguments are actually referring to the two parameters given by the operation. If you add the third argument here, it will be ignored (as there are only two operations defined).
- Click OK to close the windows and go back to diagram. The arguments are added and presented on diagram. Finally the diagram become:
- More UML sequence diagram toolset
- Full set of UML tools and UML diagrams