Creating a Sequence Diagram from a Class
- 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.
Drawing the 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: