Title: Sequence diagrams
1Sequence diagrams
Object-Oriented Design Module 4
John Leaney, Lian Loke, Lizveth Robles University
of Technology, Sydney
Contributors
John Reekie, University of Technology, Sydney
Terms of Use Creative Commons Attribution-ShareAl
ike 2.5 http//creativecommons.org/licenses/by-sa/
2.5/
2Overview
- Last OO design session, we represented the static
structure of the model for a system in a UML
Class Diagram - Classes, generalization, association
- This week we will look at UML Interaction
Diagrams - Sequence diagram
- Quick-and-dirty version
- Collaboration diagram
- Referenceshttp//www.softwarepractice.org/coursew
are/index.php/design/sequence_diagrams
3Diagrams in UML
Use case Diagram
Development Diagram
Statechart Diagram
Views
Activity Diagram
Component Diagram
Object Diagram
Sequence Diagram
Collaboration Diagram
Class Diagram
Knoernschild, p. 55
UML has a lot of different diagrams! Use them as
appropriate.
4Interaction Diagrams
- UML notation for illustrating
- how objects interact via messages
- the sequence of events and interactions between a
set of objects - A single diagram is typically drawn for a
particular scenario or use case. - Can be used at different stages in system
development. - We will focus on the use of interaction diagrams
at the design stage.
5Common Notation
Client
Client
c1Client
instance
named instance
return value message(parameter
parameterType) returnType
s calculateSalary(hours) s calculateSalary
(hours Integer) Double
6An example sequence interaction diagram
Scenario Check campaign budget
Note The blackened segments show when the object
has the focus of control. You do not normally
show this on your diagrams.
7Sequence Diagram
- Shows the sequence of events that occur in a
scenario - Shows the detailed interaction between objects
- Good for presenting sequence or time ordering of
messages - Constrained format in which more objects are
added to the diagram horizontally to the right - i.e., can run out of room on the paper
8Sequence Diagram Notation
- Messages
- Focus of control and activation boxes
- Illustrating Returns
- Messages to self or this
- Creation of instances
- Object Lifelines and Object Destruction
- Iteration or looping
- Conditional messages
9Notation Samples 1
synchronous message synchronised with source
by a return messagein context of overall normal
message flow
anonymous objectnot named
Client
getName ( )
Activation boxWhen this message trace is active
return message
object lifeline
10Notation Samples 2
instance creation message
Campaign
named object
addNewAdvert( )
synchronous message
create( ) ltltcreategtgt
adv1 Advert
autoDestroy()
message to self
object destruction
X
11Notation Samples 3
12Notation Samples 4
A
B
C
calculate (x )
xgt10calculate( )
xlt10 calculate( )
Mutual exclusive conditional messages
13Synchronous and Asynchronous messages
Time constraints are mainly used in real-time
systems
14Example - Sequence Diagram 2
Scenario Add a new advert to a campaign with
boundary and control classes
15Quick-and-dirty
- Sometimes we want to quickly sketch the essence
of the interaction without bothering about
correct syntax - Here we present a no-frills way of drawing
sequence diagrams, called Quick-and-dirty - Suited to drawing by hand
- Of course, when formally documenting your design,
you should use formal UML syntax - ? Use Quick-and-dirty sequence diagrams in your
project workbook to explore and present your
design
16Sample 1 Quick-and-dirty
named instance
anonymous instance
player
hand
Card
valueHand
getValue
totalValue
synchronous message
addCard(aCard)
17Sample 2 Quick-and-dirty
addAdvert
addAdvertUI
CampaignManager
startInterface
selectClient
asynchronous message
18Collaboration Diagram
- Shows the messages sent between objects without
the linear order shown in a sequence diagram. - Concentrates on the collaborations between
objects. - Better than sequence diagrams for illustrating
complex branching, iteration, and concurrent
behaviour.
19Example - Collaboration Diagram 1
Scenario Register payment of a sale
direction of message
first internal message
1 makePayment(cashTendered)
makePayment(cashTendered)
Register
Sale
link line
1.1 create(cashTendered)
first message
parameter
Payment
creation indicated with a
instance
"create" message
Ref Larman
20Collaboration Diagram Notation
- Links
- Messages
- Messages to self or this
- Creation of instances
- Message Number Sequencing
- Conditional messages
- Iteration or looping
21Example - Collaboration Diagram 2
Scenario Add a new advert to a campaign
Client is responsible for providing data about
campaigns to AddAdvert
Bennett, Figure 9.13
22Example - Collaboration Diagram 3
Can show different possible allocations of
responsibility
Scenario Add a new advert to a campaign
Here Client is responsible for providing
AddAdvert with a list of its campaigns. AddAdvert
is now responsible for getting campaign details
directly from Campaign objects.
Bennett, Figure 9.14