Sequence Diagram in UML
Posted by Ravi Varma Thumati on December 6, 2010
In the last article, we saw Activity diagrams, the notations to be used in Activity diagrams, their significance, and how to build an Activity diagram. We then made an Activity diagram for a specific scenario in our Courseware Management system. One of the most widely used dynamic diagrams in UML is the Sequence diagram, which is the topic of our discussion today. By the end of this article, you will know what a Sequence diagram is, what its elements are, and, you will be able to create Sequence diagrams for your system.
Basics
A Sequence diagram depicts the sequence of actions that occur in a system. The invocation of methods in each object, and the order in which the invocation occurs is captured in a Sequence diagram. This makes the Sequence diagram a very useful tool to easily represent the dynamic behavior of a system.
A Sequence diagram is two-dimensional in nature. On the horizontal axis, it shows the life of the object that it represents, while on the vertical axis, it shows the sequence of the creation or invocation of these objects.
Because it uses class name and object name references, the Sequence diagram is very useful in elaborating and detailing the dynamic design and the sequence and origin of invocation of objects. Hence, the Sequence diagram is one of the most widely used dynamic diagrams in UML.
Defining a Sequence diagram
A sequence diagram is made up of objects and messages. Objects are represented exactly how they have been represented in all UML diagrams—as rectangles with the underlined class name within the rectangle. A skeleton sequence diagram is shown in Figure 8.1. We shall discuss each of these elements in the next section:
Figure 8.1: Sample Sequence diagram, showing the general elements of a sequence diagram
An object can call itself recursively. An arrow commencing and ending at itself denotes this.
Defining a Sequence diagram
Let us take a look at the building blocks of a Sequence diagram.
Elements of a Sequence diagram
A Sequence diagram consists of the following behavioral elements:
Creating a Sequence Diagram
If your UML tool supports modeling class diagrams, you should be able to model Sequence diagrams as well. We will be using the Poseidon Community Edition tool to draw the class diagram. You can use any tool that you are comfortable with.
Figure 8.2: a screen shot of the Poseidon tool.
The screen shot of the Poseidon tool in Figure 8.2 shows the different options to model Sequence diagrams and define interactions between objects participating in these interactions.
Case Study—Courseware Management System
From the discussion in the previous section, we are clear on the different notations that are used in Sequence diagrams. Armed with this knowledge, we will proceed to design a Sequence diagram for our Courseware Management System case study application. Because a Sequence diagram represents the dynamic flows in an application, we will aim to represent one of the flows using a Sequence diagram. In Article 3, we had defined the following use cases for the Courseware Management System:
- View courses
- Manage topics for a course
- Manage course information
- View course calendar
- View tutors
- Manage tutor information
- Assign courses to tutors
For these use cases, we had modeled the classes and interfaces using the class diagram in Article 4 (parts 1 and 2). Now, we will combine the flow defined by the use cases and the classes involved in the use cases together to represent the different flows in the Courseware Management System.
As an example, we will represent the “Manage course information” flow using a Sequence diagram.
Identifying the activities and transitions for managing course information
The “Manage course information” flow contains one participant: the Course Administrator. Apart from this, there are a few entities with which the course administrator interacts in this flow—Course, Topic, and Tutor. The sequence of steps carried out in the “Manage course information” flow are:
- A user who is a course administrator invokes the manage course functionality.
- The manage course functionality of the course administrator invokes either the course creation or course modification functionality of a course.
- After the course is either created or modified, the manage topic functionality of the course administrator calls the topic creation or modification functionality of a topic.
- Finally, the user invokes the assign tutor to course functionality of the course administrator to assign a tutor to the selected course.
Now, let us model these steps into a Sequence diagram for the “Manage course information” functionality.
Sequence diagram
Figure 8.3: Activity diagram for the “Manage course information” flow
Figure 8.3 shows the Sequence diagram for the “Manage course information” flow. The Sequence diagram uses the CourseAdministrator, Course, Topic, and Tutor classes that we had defined earlier (see Article 4, parts 1 and 2) when we modeled the different classes in the Courseware Management System. The methods used in the Sequence diagram are the same methods that we had defined for these classes previously.
Summary
A Sequence diagram, as we saw today, represents the interaction among the different objects of a system. In the next article of this series, we will learn about Collaboration diagrams that are similar to Sequence diagrams, but represented as a set of graphs.
Ingeborg Sarvas said
It can be rare to find a specialist in whom you will surely have some confidence. In the world of today, nobody actually cares about showing others exactly how in this subject matter. How blessed I am to have actually found such a wonderful blog as this. It’s people like you that make a genuine difference these days through the concepts they share.
StarCraft 2 guide to said
Magnificent content, I’m a great enthusiast of your article content and discussions, keep up the good work!