Object Oriented Analysis and Design
Lecture 09 Sequence Diagrams
Mehwish Kayani
[email protected] What are Interaction Diagrams?
Interaction diagrams describe how groups of
objects collaborate
Typically an interaction diagram captures the
behavior of a single use case
shows a number of example objects, and the
messages passed between them to realize the use
case
There are two types of Interaction diagrams:
Sequence diagrams
Collaboration diagrams
2 Lecture 18 CS540 Software Design
Sequence Diagrams
One sequence line per object called object lifeline
Lines between objects represent method calls and
returns
Main components of a sequence diagram
describing a single scenario
representing "typical" objects
object lifelines
message passing
conditional
iterative
returns
The charm
works well in a scenario-driven design environment
better characterization of object-oriented systems
simple and visually suggestive
3 Lecture 18
Sequence Diagram
Captures dynamic behavior (time-
oriented)
Sequence Diagram
Captures dynamic behavior (time-oriented)
Purpose
Model flow of control
Illustrate typical scenarios
Sequence Diagrams
A sequence diagram shows an interaction
arranged in time sequence
the objects (not the classes)
the messages that pass between them
when an interaction occurs
Sequence Diagram: Example
seque
diagra
:Caller :Operator :Callee
call
ack
number
call
ack
transfer time
talk
Message Type
Simple Message
Control is passed from one object to another without providing
details
Synchronous Message
The sending object pause to wait for a result
Asynchronous Message
The sending object does not pause to wait for the result
Return Message
This message indicates a return from a procedure call
Message Types
Simple Message Synchronous Message
Return Message Asynchronous Message
Step 1: Start with the Use Case
POS Use Case : Handle Returns
Handle Return:
1. A customer arrives at a checkout with items to return.
2. The cashier uses the POS system to enter the receipt
number
3. The system presents details after verifying the receipt.
4. The system verified the return date limit.
5. The system updates the inventory.
6. Product is added to the inventory and a new receipt is
generated.
Step 2: Draw the Sequence Diagram
Collaboration Diagrams
In sequence diagrams, time is implicitly represented
as going "down the page"
object lifelines
message sequence top to bottom
In collaboration diagrams, the collaboration (message
passing sequence) shows the passing of time
no explicit visual representation of passing time
Collaboration Diagram
Collaboration Diagrams (summary)
Individual objects are icons in the diagram
identified by class name, and possibly an instance name
Flow of time is tracked by message numbers
phases of activity are harder to keep track of
Same iteration and conditional constructs
More emphasis on the objects and their names
Summary
Interaction diagrams represent interaction among
classes/objects
sequence diagrams are simplest, but time is linear and
hard to represent complex interactions over time
collaboration diagrams represent time via message
sequence numbers; easier to show a complex sequence,
harder to follow the flow
Exercise
Draw Sequence diagrams
representing the following
interactions:
A client searches for a book in a
library. He or she then asks to
borrow the book. If a copy of this
book is available, a loan object is
created.