Understanding the Basics of Sequence Diagrams

While there is an assumption that Sequence Diagrams were made for developers, the truth is that a company’s business staff could use such diagrams to communicate how exactly the business presently currently works by illustrating how the different business objects interact. In addition to this, a business-level sequence diagram may also be used as a “requirements document” to showcase the prerequisites for a future system implementation. It is at the requirements period of a certain project that analysts can take use cases to the next level by offering a more formal level of refinement. It is when this happens that use cases are often refined into sequence diagrams. 

A company’s technical staff could utilize sequence diagrams in order to document the behaviour of a future system. It is during the design period that developers and architects utilize the diagram to showcase the system’s object interactions, thereby putting out a more fleshed out overall system design. Besides being used to design new systems, sequence diagrams could also be utilized to document how objects in an existing system currently interacts. This type of documentation is very useful when moving a system to another organization or person.

Understanding the basics of Sequence Diagrams

As mentioned the aim of a sequence diagram is to define event sequences, which would have a desired outcome. The focus is more on the order in which messages occur than on the message per se. However, the majority of sequence diagrams will communicate what messages are sent and the order in which they tend to occur.

1. Lifelines

When drawing a sequence diagram, remember that lifeline notation elements are placed across the top of the diagram. Lifelines are representative of roles or object instances that partake in the sequence being modeled. From a visual perspective, lifelines are shown as a box with a dashed line descending from the center of the bottom edge. The lifeline’s name is placed inside the box. Additionally, the lifeline name is underlined. What this means is that the lifeline represents a specific instance of a class in a sequence diagram.

2. Messages

For the sake of readability, the first message of a sequence diagram always starts at the top and is located on the left side of the diagram. Subsequent messages are then added to the diagram slightly lower then the previous message. To show an object or lifeline sending a message to another object, you draw a line to the receiving object with a solid arrowhead (if a synchronous call operation) or with a stick arrowhead (if an asynchronous signal). The message/method name is placed above the arrowed line. The message that is being sent to the receiving object represents an operation/method that the receiving object’s class implements.

3. Guards

When modeling object interactions, there will be times when a condition must be met for a message to be sent to an object. Guards are conditions that need to be used throughout UML diagrams to control flow. Remember that a guard could only be assigned to a single message. To draw a guard on a sequence diagram, you placed the guard element above the message line being guarded and in front of the message name, as shown below.

4. Alternatives

This type of elements are utilized to indicate a mutually exclusive choice that exists between more that one message sequence. Alternatives allow the modeling of the “if then else” logic (e.g., if you were to buy three items, then you get 20% off your purchase; whereas you get 10% off your purchase). As you can see below, will notice that an alternative combination fragment element is drawn using a frame. The word “alt” is placed inside the frame’s name box.

5. Options

The option combination element or fragment is utilized to model a sequence that will occur provided it is given a certain condition. If not, the sequence does not occur. An option is usually used to model a simplistic ”if then” statement, for example, if there are less than five donuts present on the counter, then make two dozen more. The image below uses an option combination fragment since a lot of messages have to be sent if the student’s past due balance is equal to zero. According to the diagram, if a student’s past due balance equals zero, then the addStudent, getCostOfClass, and chargeForClass messages are sent. If the student’s past due balance does not equal zero, then the sequence skips sending any of the messages in the option combination fragment. We include a guard for the option; however, the guard is not a required element.

6. Loops

Loops are rather basic and easy to grasp. This is something that is used when you need to model a repetitive sequence. In UML 2, modeling a repeating sequence has been improved with the addition of the loop combination fragment. The loop combination fragment is very similar in appearance to the option combination fragment. You draw a frame, and in the frame’s namebox the text “loop” is placed. Inside the frame’s content area the loop’s guard is placed towards the top left corner, on top of a lifeline.

Learn How Creately Diagrams works

Learn How Creately Diagrams works