Swe-Sequence Diaram 2023

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 45

Lesson 3: Sequence Diagrams

Introduction
• The dynamic interaction of objects is modeled in, uml, using the
interaction diagrams.
• Interaction diagrams are models that describe how group of objects
collaborate to realize some behavior.
• An interaction diagram shows the interactive behaviour of the system
and the messages that are passed between the objects within the
use case.
• There are two kinds of interaction diagrams: sequence diagrams and
collaboration diagrams. These two diagrams are equivalent in the
sense that any one diagram can be derived automatically from the
other. However, they are both useful.
– Communication Diagrams: Illustrate object interactions organized around the
objects and their links to each other
– Sequence Diagrams: Illustrate object interactions arranged in time sequence
• This lesson illustrates in more details sequence diagram.
Sequence Diagrams
• Sequence diagrams describe in detail how actors use use cases;
they can also model external business processes the new system
will support (e.g., processing a book order)
• An interaction is a behavior that consists of a set of messages
exchanged between external and system objects.
• Interactions consist of one or more messages. Interactions
may be synchronous (e.g., calling someone on the phone), or
asynchronous (e.g., sending someone email).
• Sequence diagrams defined during requirements analysis
should not:
• include design objects;
• specify message signatures in any detail;
Student Guide

• Students should be encouraged to construct a


sequence diagram for one of their own projects
(preferably one that they have written use-cases for).
Objectives
• To discuss when to use sequence diagrams
• To present the UML sequence diagram notation
• Understand the syntax and semantics of UML sequence
diagrams
• Make interaction models using UML sequence diagrams
Sequence Diagrams
• Sequence diagrams:
– are used to display the interaction between users, screens and object instances within the
system in the sequential order that those interactions occur.
– is a dynamic model of a use case, showing the interaction among classes during a
specified time period.
– shows the objects involved in a scenario and the sequence of messages exchanged
between the objects that are needed to carry out the functions described by the scenario.
– Illustrates the classes that participate in a use case and how they share responsibilities via
messages
– Shows the messages that pass between classes over time for one Use Case
– can be used in conjunction with use-cases at the requirements phase, or at the design phase
they can be used to show the system’s behavior that corresponds to a use-case
– Can model simple sequential flow, branching, iteration, recursion and concurrency.
– don’t show the structural relationships between objects
– can be used to generate test cases for the software product
• Frequently these diagrams are placed under Use Cases or Components in the model
to illustrate a scenario, or common set of steps followed in response to an event that
generates an outcome.
• The model includes what initiates activity in the system, what processing and
changes occur internally and what outputs are generated.
Sequence Diagram concepts
• A sequence diagram shows interaction among objects as a two
dimensional chart.
• The chart is read from top to bottom.
• The objects participating in the interaction are shown at the top of the
chart as boxes attached to a vertical dashed line.
• The messages are shown in chronological order from the top to the
bottom. That is, reading the diagram from the top to the bottom would
show the sequence in which the messages occur.
• Sequence diagrams demonstrate the behavior of objects in a use
case by describing the objects and the messages they pass
Sequence Diagrams’ Dimensions

X-Axis (objects)

member: :Book
book:Book
LibraryMember Copy

borrow(book) Object
Life Line
ok = mayBorrow()
Y-Axis (time)

message

Activation
[ok] borrow(member) box
setTaken(member)

condition

Sequence Diagrams 8
Sequence Diagram notation
AN ACTOR
Participates in a sequence by sending and/or
receiving messages

AN OBJECT anObject:aClass
Participates in a sequence by sending and/or receiving
messages
A LIFELINE
Denotes the life of an object during a sequence
A FOCUS OF CONTROL
Denotes when an object is sending or receiving
messages
A MESSAGE
Conveys information from one object to another A Message()
one
OBJECT DESTRUCTION
An X is placed at the end of an object’s lifeline to show x
that it is going out of existence
Sequence diagram notation: object

:Object 1: Class_name :Object 2

Actors
Objects

UML Syntax : [<object_name> ]: <class_name>


Sequence diagram notation: Lifeline

:Object 1 :Object 2

Lifelines
Identify the existence of the object over time.
Sequence diagram notation: activation
:Object 1

Activations
Indicate when an object is performing an action
Sequence diagram notation: Messages
:Object 1 :Object 2

message

Messages
Indicate the communications between objects
Messages
• Messages:
– are used to model the content of communication between objects.
– are used to convey information between objects and enable objects to request services of
other objects.
– is the invocation of an object's operation from another (possibly the same) object.
– is shown as a horizontal solid arrow from the lifeline of one object to the lifeline of
another object.
• The first message of a sequence diagram always starts at the top and is typically
located on the left side of the diagram for readability.
• Subsequent messages are then added to the diagram slightly lower then the previous
message.
• The message instance has a sender, receiver, and possibly other information
according to the characteristics of the request.
• The sender will send the message and receiver will receive the message.
• In case of a message from an object to itself, the arrow may start and finish on the
same object symbol.
• A message is labeled at minimum with the message name. Arguments and control
information (conditions, iteration) may be included.
Sequence dg. from use case

15
Messages types
• The message arrows represent the communications between two objects
in a sequence diagram. It goes from the lifeline of one object to that of
another object
• According to the arrows symbols the messages classified to:
– Synchronous message- the caller has to wait for the receiving
object to complete execution of the called operation before it can
resume execution.
• Symbol:
– Asynchronous message – The caller can execute immediately after
sending the message, it does not has to wait for the recipient to
handle the message
• Symbol:
• OR
– A return of control from the synchronous message
• Symbol
Async Message Example

Synchronous message
Coming up: Components: Guards Asynchronous message
Return message
Synchronous Messages

• Nested flow of control, typically implemented as an


operation call.
– The routine that handles the message is completed
before the caller resumes execution.

:A :B

doYouUnderstand()
return
Caller
yes (optional)
Blocked
Messages types
Synchronous & Asynchronous Messages

Nested Flow Asynchronous Flow


teller : Order : Article appl err handl alarm

getValue unknown

price ring

setID log

Example Example

Price need to be Ring is executed, while


finished, before teller the control flow is
can do another operation returned to err handle
(getName) and appl
Special message types

• self-delegation (self call)


• <<create>>
• <<destroy>>
Flow of Control
Self message (Self calls)

When modeling a sequence diagram, there will be times that an object will need to send a
message to itself.
This is drawn as an arrow looping back on itself as shown.
A self message can represent a recursive call of an operation, or one method calling another
method belonging to the same object.
It is shown as creating a nested focus of control in the lifeline’s execution occurrence.
A typical example of this is close. You can place a button on a form and when you click it, it
Object Creation
• An object may create another object via a
<<create>> or new message.
– Object life starts at that point

Create
B

X
Return
Deletion
24
Lifeline
Object Destruction

• An object may destroy another object via a


<<destroy>> message.
– An object may destroy itself.
– Object’s life ends at that point

:A :B

<<destroy>>

25
Message Specification
• Every synchronous and asynchronous arrow must be labeled
with a message specification on top of the message arrow.
• The message format :

return_variable_name = message_name (param_list)

– Both the i) return_variable_name and ii) the “=“ sign are


suppressed if there is no return value
– message_name is never suppressed (required field)
– param_list is a list of arguments separated by commas and
is suppressed when there is no argument
Message Specification
Examples of Sequence Diagram’s message specification

• age = getAge or age = getAge( )


– message specifies that the return value from getAge
operation is assigned to the variable age. Note that age is
a variable accessible by the object that sent the message

• checkStatus (flag = status, machine)


– message specifies that checkStatus operation passes a
parameter and gets back the status information which
assigned to a “local” variable, flag. (local meaning the
object that sent the message)
Message Control information
Two kinds of control information:
• message conditions
– A guard (condition) is something that is true or false
– message is sent only if the condition is true
– syntax: ‘[‘ expression ’]’ message-label
– The message is sent only if the condition is true
– example: [ok] borrow(member)
• iteration marker: *
– message sent to multiple receiver objects
– syntax: * [ ‘[‘ expression ‘]’ ] message-label
– The message is sent many times to possibly multiple
receiver objects.
29
Control information

For example, a [condition] has to be met before the object of


class 2 can send a message() to the object of class 3.
Iteration

• Iteration shown with an asterisk.


• Each StaffMember will be selected in turn
• Once selected, the CalculateBonus message will be sent to the one
currently selected
• There is only one loop!
Sequence Diagrams: Iteration & Condition

ChangeProcessor CoinIdentifier Display CoinDrop


Passenger

*insertChange(coin) lookupCoin(coin)

price
Iteration
displayPrice(owedAmount)

[owedAmount<0] returnChange(-owedAmount)
Condition
Use Cases for a
Meeting Scheduling System
Sequence Diagram
Object

:SimpleWatch :LCDDisplay :Time


:WatchUser

pressButton1() blinkHours()
pressButton1() blinkMinutes()

pressButton2() incrementMinutes()
refresh()
pressButtons1And2()
commitNewTime()
stopBlinking()

Message
Activation

Sequence diagrams represent behavior as interactions


Sequence diagram exmple

36
Application
Example:
Normal Flow of Events:

1. Customer submits a search request to the system.


2. The system provides the customer a list of recommended
CDs.
3. The customer chooses one of the CDs to find additional
information.
4. The system provides the customer with basic (market)
information & CD Reviews
5. The customer calls the maintain order use case.
6. The customer iterates over 3 through 5 until finished
shopping.
7. The customer executes the checkout use case.
8. The customer leaves the website.
Application
Example:

Slide 38
Sequence diagrams - example

Caller Operator Callee

call

ack

number
call

ack
transfer
talk
time
Summary

• The reason the sequence diagram is so useful is


because it shows the interaction logic between the
objects in the system in the time order that the
interactions take place.
• Interacting objects are represented by lifelines arrayed
across the diagram.
• Time is represented down the diagram.
• The exchange of messages is shown by message
arrows arranged down the diagram.
Activity

• Develop sequence diagram for Customer Loses a


Tape specification using UML tool

Customer walks to the central desk and tells the clerk he


has lost the videotape he rented. The clerk looks up the
record of the rental and prints put a document detailing
which tape was lost. The clerk then asks the customer
to speak with the manager. The clerk hands the
manager the report on the lost tape and the manager
asks the customer to pay a fee based on the age and
original cost of the video. The customer pays the fee
and his records are updated to show the resolution of the
rental.
Quiz

• The focus in a sequence diagram is on __________________


• A. how actors interact with objects to realize a given use case
• B. messages sent by actors to other objects
• C. when an object is being created
• D. when messages are being destroyed
• E. time ordering of messages being passed between objects

• The modeling focus of the interaction diagram is at the
_____ level while the modeling focus on the class
diagram is at the _____ level.
a. class, object
b. interaction, class
c. class, interaction
d. object, class
e. high, low

Ans: d
• The focus in a sequence diagram is on __________________
a. How actors interact with objects to realize a given use case
b. Messages sent by actors to other objects
c. when an object is being created
d. when messages are being destroyed
e. time ordering of messages being passed between objects
• Ans: e
• The order of messages on a sequence diagram goes from ____ to
_____.
a. right to left
b. bottom to top
c. left to right
d. top to bottom
e. left to right, top to bottom
• Ans: d

You might also like