Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 36

Sequence Diagrams

By
Dr. B.Kalaavathi
Interaction Diagrams
• UML Specifies a number of interaction
diagrams to model dynamic aspects of the
system
• Dynamic aspects of the system
 Messages moving among objects/classes
 Flow of control among objects
 Sequences of events

Coming up: Dynamic Diagram Types


Dynamic Diagram Types
• Interaction Diagrams - Set of objects or roles and the
messages that can be passed among them.
 Sequence Diagrams - emphasize time ordering
 Communication Diagrams - emphasize structural
ordering
• State Diagrams
 State machine consisting of states, transitions, events
and activities of an object
• Activity & Swimlane Diagrams
 Emphasize and show flow of control among objects

Coming up: Sequence Diagrams


Sequence Diagrams
• Describe the flow of messages, events, actions
between objects

• Show concurrent processes and activations


• Show time sequences that are not easily depicted in
other diagrams

• Typically used during analysis and design to document


and understand the logical flow of your system

Emphasis on time ordering!


Key parts of a sequence diag.
• participant: an object or entity that acts in the
sequence diagram
• message: communication between participant
objects
• the axes in a sequence diagram:
 horizontal: which object/participant is acting
 vertical: time (down -> forward in time)
Sequence Diagram

Coming up: Components


Sequence Diagram
Time Increasing -->

All lines should be horizontal to indicate


instantaneous actions. Additionally if ActivityA
happens before ActivityB, ActivityA must be above
activity A

Lower = Later!
Coming up: Components
Representing objects
• Squares with object type, optionally preceded
by object name and colon
 write object's name if it clarifies the diagram
 object's "life line" represented by dashed vert. line
Messages between objects
• message (method call) indicated by horizontal arrow
to other object
 write message name and arguments above arrow
Messages, continued
• message (method call) indicated by horizontal
arrow to other object
 dashed arrow back indicates return
 different arrowheads for normal / concurrent
(asynchronous) methods
Diagonal Lines

:Student :Registration
System
Time=A GetDetails()

Time=B

• What does this mean?


• when modelling a real-time system, or even a time-bound business process,
it can be important to consider the length of time it takes to perform actions.
By setting a duration constraint for a message, the message will be shown
as a sloping line.
Components
Objects: aStudent is a specific
instance of the Student class

Generic (unnamed)
Specific Generic
objects(unnamed)
Instance of an objects of class type Seminar
Object and Course

Coming up: Components


Components

execution
lifeline

Coming up: Components


Lifetime of objects
• creation: arrow with
'new' written above it
 notice that an object
created after the start of
the scenario appears
lower than the others
• deletion: an X at bottom
of object's lifeline
 Java doesn't explicitly
delete objects; they fall
out of scope and are
garbage-collected
Components

Method call

Return value

Coming up: Components


Components
c : Client o : ODBCProxy
create()
: Transaction

setActions(a, b, c)
setValues(a, 3, 4)

setValues(b, c, 7)

(committed)
destroy()

create()
destroy()
Synchronous message
Asynchronous message
Coming up: Components: Guards
Return message
• a synchronous message is used when the sender
waits for the receiver to process the message
and return before carrying on with another
message.
• An asynchronous message is used when the
message caller does not wait for the receiver to
process the message and return before sending
other messages to other objects within the
system.
Indicating method calls
• activation: 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
 nest to indicate recursion

Activation

Nesting
Async Message Example

Synchronous message
Asynchronous message
Coming up: Components: Guards
Return message
Indicating selection and loops

• frame: box around part of a sequence


diagram to indicate selection or loop
 if -> (opt) [condition]
 if/else -> (alt) [condition], separated by
horizontal dashed line
 loop -> (loop) [condition or items to loop
over]
Components: alt/else

Coming up: Components: option


Components: option

Coming up: Components: loop


Components: loop

Coming up: In class exercise


linking sequence diagrams
• if one sequence diagram is too large or refers to another diagram,
indicate it with either:
 an unfinished arrow and comment
 a "ref" frame that names the other diagram
Rules of thumb
• Rarely use options,loops,alt/else
 These constructs complicate a diagram and make
them hard to read/interpret.
 Frequently it is better to create multiple simple
diagrams

• Create sequence diagrams for use cases when it


helps clarify and visualize a complex flow

• Remember: the goal of UML is communication


and understanding
Summary
• Sequence diagrams model object interactions with an
emphasis on time ordering
• Method call lines
 Must be horizontal!
 Vertical height matters! “Lower equals Later”
 Label the lines
• Lifeline – dotted vertical line
• Execution bar – bar around lifeline when code is running
• Arrows
 Synchronous call (you’re waiting for a return value) – triangle
arrow-head
 Asynchronous call (not waiting for a return) – open arrow-head
 Return call – dashed line

Coming up: In class exercise


Example sequence diagram
Sequence Diagram of an Online Exam System
In class exercise

• Draw a sequence diagram for:


 In Beauty and the Beast kitchen items came to
life. Draw a sequence diagram for making a
peanut butter and jelly sandwich if the
following objects are alive: knife, peanut butter
jar (and peanut butter), jelly jar (and jelly),
bread, plate. I may or may not want the crusts
cut off. Don’t forget to open and close things
like the jars, and put yourself away, cleanup,
etc…
Coming up: In class exercise
In class exercise

• Draw a sequence diagram for:


 Returning a movie to Netflix. When you return
it a person scan’s it in, the s/w detects that
and then goes through a sequence of steps to
get the new movie to you. Think of the
different classes that would be involved:
Queue, Shipping, Inventory, UserAccount,
other classes??

Coming up: In class exercise


In class exercise
• Draw a sequence diagram for:
 Adding a picture to Flickr (or any online image
database). Login, pick an album, upload a picture,
etc… Think about the software classes that would be
involved – WebGUI (think of this as reporting what the
user does), UserAccount, Album, AlbumList, etc…

 Don’t forget to check and update their current disk


usage. For this diagram show the check coming back
as acceptable.. you would do a second diagram for
them running over quota.

Coming up: In class exercise


In class exercise

• Draw a sequence diagram for:


 Getting on a flight. Start at home, check in at
the counter, go through security, and end up at
the gate. (If you have time during the exercise,
get yourself to your seat.)
• You may get searched in security

Coming up: In class exercise


In class exercise

• Draw a sequence diagram for:


 Getting money from an ATM machine
• Treat each part of the ATM as a class
 Money dispenser
 Screen
 Keypad
 Bank computer
 Etc…

Coming up: References


References

• Example diagrams from:


http://www.ibm.com/developerworks/ration
al/library/3101.html

• Also see Booch G.,The Unified Modeling


Language User Guide, ch 19.

Coming up: References

You might also like