Lecture 27
Lecture 27
Ashish Kumar
Dept. of CSE
Manipal University Jaipur
1
Sequence Diagram
An "interaction diagram" that models a single scenario
executing in the system
perhaps 2nd most used UML diagram (behind class
diagram)
Shows how objects communicate with each other over
time.
That is, sequence diagrams are used to model object
interactions arranged in time sequence and to
distribute use case behavior to classes.
They can also be used to illustrate all the paths a
particular use case can ultimately produce.
The diagram captures the behavior of a single use
case.
It shows objects and the messages that are passed
between these objects in the use case. 2
When to use a sequence diagram
A good design can have lots of small
methods in different classes.
Increasin
Y-Axis (time)
g Order
6
Object / Participant & Their Lifelines
Each object/participant has a corresponding
lifeline.
Each vertical dotted line is a lifeline,
representing the time that an object exists.
Squares with object type, optionally preceded by
"name :" :Name Object
Life line
Activation
7
Activation
Also known as Focus of control.
Thick box over object's life line; drawn when
object's method is on the stack
either that object is running its code, or it is on
the stack waiting for another object's method
to finish
Activation
nest to indicate recursion
Nesting
8
Object / Participant Naming
Syntax: [instanceName][:className]
Name classes consistently with your class
diagram (same classes).
Include instance names when objects are
referred to in messages or when several objects
of the same type exist in the diagram.
9
Messages
Messages (or signals) on a sequence diagram are
specified using an arrow from the participant
(message caller) that wants to pass the message
to the participant (message receiver) that is to
receive the message.
A Message (or stimulus) is represented as an
arrow going from the sender to the top of the
focus of control (i.e., execution occurrence) of the
message on the receiver's lifeline.
A message is labeled at minimum with the
message name.
Arguments and control information (conditions,
iteration) may be included.
Self calls are also allowed. 10
Message Type Notations
11
Object Creation & Destruction
Object Creation: when an element is
created during an interaction, the
communication that creates the element is
shown with its arrowhead to the element.
Object Destruction: When an element is
destroyed during an interaction, the
communication that destroys the element
is shown with its arrowhead to the
elements lifeline where the destruction is
marked with a large X symbol.
12
Frame
Box around part
of diagram to
indicate if or loop
if -> (opt)
[condition]
if/else -> (alt)
[condition],
separated by
horizontal dashed
line
loop -> (loop)
[condition or
items to loop over]
13
How to Produce Sequence Diagrams
Decide on Context: Identify behavior (or use
case) to be specified
Identify structural elements:
(a) Model objects (classes)
Identify which objects and actors will participate
(b) Model lifelines
Set the lifeline for each object/actor
(c) Model messages
Lay out the messages from the top to the bottom of
the diagram based on the order in which they are
sent
(d) Model activations
(e) Model Timing constraints
Validate, refine and elaborate as required 14
Example
15
Example : Use Case Level
16
Example
17
Thank You
18