SAD Section 9
Table of Contents:
Sequence Diagram
o Sequence Diagram Elements
Actor(s)
Object(s)
Life lines
Activation Bar
Messages
o Synchronous
o Asynchronous
o Reply
o Create object
o Delete object
o Self-message
Optional == if statement
Alternative == if , else // if , else if , ......, else
Loop
Sequence Diagram:
Is a type of diagram used in system design to illustrate the order of interactions that
occur between different objects or components in a system over time. It provides a
clear, step-by-step temporal view of how a particular process or use case unfolds.
The Relationship between Sequence Diagram, Use Case Diagram, and Class
Diagram
1. Use Case Diagram:
This is the first step in system analysis.
It identifies the functions or scenarios the system will handle, such as "Login,"
"Book a Trip," or "Add Product to Cart."
It doesn’t provide details; rather, it acts as a map showing how actors interact with
the system.
Connection to Sequence Diagram:
When creating a Sequence Diagram, we focus on a specific scenario from the Use
Case Diagram.
For example, if there is a Use Case called "Login," it will have a Sequence Diagram
that explains the steps involved in that scenario.
2. Class Diagram:
This explains the internal structure of the system, showing the classes and their
relationships.
It tells us what objects (instances of classes) will be created during the execution of
scenarios.
Connection to Sequence Diagram:
The Sequence Diagram shows how objects (defined in the Class Diagram) will
interact with each other in a specific scenario.
In other words, the Sequence Diagram relies on the existence of objects that come
from the Class Diagram.
Why Is the Sequence Diagram Important?
o Helps in understanding and explaining how a specific use case works.
o Acts as a visual reference to document system behavior for future development or
maintenance.
o By mapping out interactions, it’s easier to spot missing steps, redundant processes,
or potential issues.
o Provides a link between high-level use case descriptions and the low-level class
design, making the transition from analysis to design seamless.
Components of a Sequence Diagram:
1. Actors: is anyone or anything that needs to interact with the system to exchange
information. Actors can be (individual, group, company, server , etc……….)
2. Objects :
Represent the entities within the system involved in the interaction.
: Object
Shown as rectangles with an underlined label their names at the top.
: Student : Client : Server
: GUI : Courses : Trip
3. Lifelines:
Vertical dashed lines extending from each actor or object, representing their existence
over time.
: Student
4. Activation Bar:
Narrow rectangles on a lifeline, showing the period during which an object is
actively performing a task or handling a process.
5. Messages:
Arrows between lifelines, representing the communication or method calls
between objects.
Horizontal arrow, Write message name and arguments above the arrow.
Includes labels to describe the action (e.g., "Validate Login," "Send Confirmation
Email").
Types of Messages :
Message Description
Synchronous: A message between active objects indicates
wait semantics; the sender waits for the message to be
handled before it continues. This typically shows a method
call.
Asynchronous: With an asynchronous flow of control,
there is no explicit return message to the caller. An
asynchronous message between objects indicates no-wait
semantics; the sender does not wait for the message before
it continues. This allows objects to execute concurrently.
Reply: This shows the return message from another
message
Create: This message results in the creation of a new object. The
message could call a constructor for a class if you are working
with Java, for example.
Delete : If object’s life ends When an element is destroyed
during an interaction , This is shown as an X at bottom of
object's lifeline
Self : Showing that an object is calling one of its own
operations
Examples:
________________________________________________________________________________________
________________________________________________________________________________________
____________________________________________________________________________________________________
Example: Consider the scenario where the device requests a photo from the user. Here
the message which shows the photo being sent is a reply message.
___________________________________________________________________________________________________
Example: The Emotion-Based Music Player application starts when the user opens it.
The system requests access to the webcam, which then captures an image of the user.
The captured image is processed using a facial detection algorithm that identifies the
user’s face and predicts their mood based on their expressions. The system sends a
request to the mood database to retrieve a dictionary of possible moods. Once the
mood is identified, it is displayed to the user. The system then requests a playlist from
the music database that matches the detected mood. Finally, the generated playlist is
shown to the user, and the music begins playing.
__________________________________________________________________________________________
Example : The Caller initiates the process by picking up the phone. The Phone
responds by generating a dial tone to indicate readiness for dialing. The Caller then
dials the number, which the Phone processes and sends a ring request to the
Recipient’s phone. The Recipient’s phone rings, notifying the Recipient of the incoming
call. The Recipient picks up the call, and the Phone establishes a connection. Both the
Caller and the Recipient can now communicate, exchanging greetings like "Hello."
Alternatives(alt), Options(opt), and Loops:
Shown as a box around part of a sequence diagram
• if → (opt) [condition]
• if/else → (alt) [condition], separated by horizontal dashed line
• loop → (loop) [condition or items to loop over]
1. Alternatives: IF-Else (Conditional execution) (alt)
The interaction operator alt means that the combined fragment represents a
choice or alternatives of behavior. At most one of the operands will be chosen.
Guards are used to select the one path to be executed.
• Guards are modeled in square brackets.
• default: true
• predefined: [else]
EX: Call accept () if balance > 0, call reject () otherwise.
2. Options : An option is used to model a simple "if then" statement
Is similar to the alternation combination fragment, except that it only has one
operand
EX: Post comments if there were no errors.
3. Loops : To express that a sequence is to be executed repeatedly.
• Exactly one operand.
• Keyword loop followed by the minimal/maximal number of iterations
(min..max) or (min,max)
default: (*) .. no upper limit
Guard:
Evaluated as soon as the minimum number of iterations has taken
place.
Checked for each iteration within the(min,max)limits.
If the guard evaluates to false, the execution of the loop is
terminated
EX: The loop is executed at least once, then as long as a < 1 is true.
______________________________________________________________________________________________________
Example:
The Customer starts the process by specifying the name of an author on the Search Page
and pressing the search button. The Search Page validates the Customer's search
criteria.
1. If the author name is entered, the system sends a request to the Catalog to search
for books associated with the specified author. The Catalog processes the request
and creates the relevant search results, which are displayed on the Search Results
Page.
2. If the author name is not entered, the system skips the search and instead displays
an error message to the customer on the Search Page.
____________________________________________________________________________
Example:
The student begins by logging into the system by entering their username and password
on the User Interface (UI). The system verifies the login credentials to ensure they are
correct. Once authenticated, the student can view the details of available courses. The User
Interface sends a request to the Course Catalog service to retrieve and display the relevant
course details. After selecting a course, the student chooses to reserve it, which prompts
the User Interface to display a reservation form. The student fills out the required fields in
the reservation form and submits it. The reservation details are sent to the Reserve Course
service, which verifies the course details by querying the Course Catalog again.
Additionally, the Reserve Course service checks whether the student meets the eligibility
criteria and if seats are available for the selected course. If the student is eligible and there
are seats available, the reservation is confirmed, and the student is successfully registered
for the course.