collaboration and sequence diagrams
show how classes might interact to deliver the
functionality of a use case
are used to:
• analyze the system, then design the system
• display the interaction/behaviour of use cases
• allocate operations to classes
• refine class attributes and operations so that
classes are:
• not unduly complex
• easier to develop, test and maintain
• resilient to change
• appropriate for reuse
1
collaboration
a set of objects that interact in a specific context
interaction
messages exchanged in a collaboration to produce
a desired result; can be an event or operation
objects
labeled as object name : object class
messages
arrow indicating direction
numbered to indicate sequence
collaboration diagram
static representation of messages which could be sent
2
some notes
during analysis, collaboration and sequence diagrams are “draft”,
often not showing message signatures nor all objects
that will be present when the design is complete
class diagrams ignore the interaction shown in collaboration
and sequence diagrams, but include the attributes and operations
documented in all collaboration and sequence diagrams
3
[guard]sequence-number: result:= * message-name (parameter-list)
guard
condition that applies to the message,
usually branching is involved
sequence-number
e.g. 4 or 4.2.1
result
return value
operation-name
as in class diagrams
parameter/argument-list
names separated by commas
* multiplicity
if message is sent to a multiplicity of objects (e.g. an array)
4
use case is the :booking object
“make guest
tells itself to
indicatePrice ( )
provisional 1:availabilityQuery
reservation” 2:reserveAccomodation
5:makeProvisionalReservation
4:indicatePrice
:booking
3:create reservation
10:updateAvailableRoomsTotal
6:updateStatusToProvisional
11:displayNewReservation
7:allocateToGuest
:reservation
note: use cases can make
assumptions, and here one
assumptions is that the guest
makes the reservation 8:findGuestDiscount 9:calculateDiscountedPrice
:guest
5
use case is
“confirm
reservation” guest
1:showProvisionalReservations
2:confirmReservation
5:displayBooking
:booking
3:updateStatusToConfirmed 4:reserveAccomodation
:reservation
6
use case is “check guest
in guest” 1:checkInGuest
5:fillCorrectReservation 2:displayToday's
Reservations
:booking
3:getReservationDetails 4:displayReservationDetails
6:allocateAccomodation 12:displayRoomDirections
:reservation
8:allocateRoom
7:findSuitableRoom 11:setStatsToExercised
if this hotel’s booking procedures :room
for business travelers are different
from those for vacationing travelers,
how would you indicate that?
9:create 10:setStatusToOccupied
:guest
7
use case is “
assign staff to work on a campaign”
4:selectClient()
campaign
7:selectCampaign()
manager
10:assignStaff()
5:showClientCampaigns()
8:showCampaignStaff()
<<boundary>> 11:assignStaff() <<control>>
:AssignStaff :assignStaff
2:startInterface()
1:getClients() 3:getStaff()
6:getClientCampaigns() 12:assignStaff()
9:getCampaignStaff()
<<entity>> <<entity>> <<entity>>
:client :campaign :staffMember
13:assignStaff()
shows relation exists, but not in this use case
8
collaboration diagram for use case “buy CD”
in an online store application
:CDlist
2:findCDs()
:searchRequest :CDList
3:createCDList
1:createSearchRequest
6:getReview()
:CD :MarketingInfo :review
5:getMarketInfo()
4:createBasicInfo()
7:getArtistInfo()
customer
9:addCD()
:shoppingCart 8:getSampleCLip() :ArtistInfo
10:createOrder()
:order :sampleClip
note that this diagram still needs the following to be solved: look for and buy multiple CD’s;
createOrder ( ) also appears to add a new order; a control object is needed to control this session
9
collaboration diagram for use case “add student to course”
[c_check='no']destroy feesPaid(out paid)
[s_check='no']destroy
data entry areYouValid(crs,out s_ check)
person add(std,crs,sem)
:programEntry addCourse(crsoffOID)
:student
Window
areYouOpen(out c_check)
prereqsSatisfied(out satisfied)
prereq(out crs)
addStudent(stdOID) :course :academicRecord
areYouOpen(out c_check)
the sequence numbers *prereq(out crsOID)
are missing - use your
knowledge of the use case
to add them :courseOffering :prereqCourse
10
types of message flows
synchronous
• indicates nested flow of control
• used to ensure that state cannot be compromised by
external factors e.g. not interrupted by the operating system
• invoking object halts execution while it waits for a return
completion
• invoked object finishes
asynchronous
• signal from one object to another
• invoking object does not halt execution while it waits a return
callback
• notification of completion from invoked object
11
iteration and conditions
initiator staff scheduler participant
:person :person :person :person
call ( )
respond ( )
what's up? ( )
give meeting
details ( )
* [for all participants] inform ( )
acknowledge ( )
* [for all participants] remind ( )
acknowledge ( )
prompt ( )
show schedule ( )
[decision = OK] schedule OK'd ( )
* [for all participants]
inform ( )
12
branching and asynchronous messages
print shop
:printer :queue
customer printer
print file (file)
get status ( )
[ready] print ( )
and deletion of objects
[busy] put in queue (file)
[out of service]
call repair ( )
ready (file)
ready (file)
get next ( )
x 13
use case “place a telephone call”
:switch
S:caller R:caller
lift receiver
set dial tone ( )
* dial digit (d)
route calls
(S,
(R, N)
S)
<<create>> :connection
ring ( )
lift receiver
connect (R, S)
connect (R) connect (S)
this diagram could be extended to show the two parties disconnecting
14
15
showing
active
16
multi-
threading
17
communication diagram
listCampaigns message
may pass back too much data
from :Campaign Notation for iteration different
to that in sequence diagram
sd Add a new advert to a campaign
5: createNewAdvert 5.1: addNewAdvert
4: selectCampaign 4.1: showCampaignAdverts
3: selectClient 3.1: showClientCampaigns
:AddAdvertUI :AddAdvert newAd:Advert
:CampaignManager 2: startInterface 5.1.1: addNewAdvert
1 *[For all clients]: getClient 4.1.1: listAdverts
5.1.1.1: Advert
3.1.1: listCampaigns
3.1.1.1 *[For all client’s campaigns]: 4.1.1.1 *[For all campaign’s adverts]:
getCampaignDetails getAdvertDetails
:Client :Campaign :Advert
18
listCampaigns message
does not pass back any data
from :Campaign in this
alternative interaction
sd Add a new advert to a campaign
5: createNewAdvert 5.1: addNewAdvert
4: selectCampaign 4.1: showCampaignAdverts
4.1.2 *[For all campaign’s adverts]:
3: selectClient 3.1: showClientCampaigns getAdvertDetails
:AddAdvertUI :AddAdvert :Advert
5.1.1: addNewAdvert
:CampaignManager
2: startInterface 4.1.1: listAdverts
3.1.2 *[For all client’s campaigns]:
1 *[For all clients]: getClient getCampaignDetails
3.1.1: listCampaigns
5.1.1.1: Advert
:Client :Campaign newAd:Advert
19
Message Labels
Type of message Syntax example
Simple message. 4: addNewAdvert
Nested call with return value. 3.1.2: name = getName
The return value is placed in the
variable name.
Conditional message. 5 [balance > 0]: debit(amount)
This message is only sent if the
condition [balance > 0] is true.
Iteration 4.1 *[For all adverts]: getCost
20
Navigation links
sd checkCampaignBudget
checkCampaignBudget
2: getOverheads
:Campaign
1*[For all adverts]: getCost
The direction in which a
link can be navigated
may be shown if required.
:Advert
21
sequence diagram
sd Add a new advert to a campaign
Interaction Constraint
Frame label :CampaignManager
:Client :Campaign :Advert
getName
Interaction Operator listCampaigns Combined Fragment
loop [For all client’s campaigns] (loop)
getCampaignDetails
Sequence listAdverts
diagram loop [For all campaign’s adverts]
is enclosed in a getAdvertDetails
frame
addNewAdvert
Advert
newAd:Advert
Lifeline Activation or Execution Object creation
22
sd Interaction Name
:LifelineA :LifelineB State on lifeline showing
Synchronous pre-condition
(blocking)
message
Receive messaged
Active
Event Occurrence
(msg.recieveEvent)
Send message
Event Occurrence msg a start of
(msg.sendEvent) Execution Occurrence
Execution Occurrence
end of
Execution Occurrence
Message reply
showing return of
control
23
sd Add a new advert to a campaign
Control
lifeline
Boundary
lifeline
:AddAdvert :Client :Campaign :Advert
:CampaignManager
loop [For all clients]
getClient
:AddAdvertUI
startInterface
selectClient showClientCampaigns listCampaigns
loop [For all client’s campaigns]
getCampaignDetails
selectCampaign
showCampaignAdverts
listAdverts
loop [For all campaign’s adverts]
getAdvertDetails
createNewAdvert
addNewAdvert
addNewAdvert
Advert
newAd:Advert
24
sd Delete advert
:Campaign :Advert
listAdverts
loop getAdvertDetails
deleteAdvert
delete
Object destruction
25
sd Check campaign budget
:CampaignManager
:Client :Campaign :Advert
getName
listCampaigns
loop [For all client’s campaigns]
getCampaignDetails
checkCampaignBudget
loop [For all campaign’s adverts]
getCost Reflexive
message
getOverheads
26
sd Check campaign budget
:Client :Campaign :Advert
:CampaignManager
getName Shading showing the
focus of control
listCampaigns
loop [For all client’s campaigns]
getCampaignDetails
checkCampaignBudget
loop [For all campaign’s adverts]
getCost
getOverheads
Reply with the
return-value shown
budget =
checkCampaignBudget
27
sd Check campaign budget
Object selector notation
:CampaignManager campaign[i] advert[j]
:Client
:Campaign :Advert
getName
listCampaigns Interaction constraint
loop [i=1;i<=campaign.count; i++ ] refers to variable used in
getCampaignDetails
object selector notation
checkCampaignBudget
loop [j=1;j<=advert.count; j++ ]
getCost
getOverheads
28
sd Check campaign budget
:CampaignManager campaign[i] advert[j]
:Client
:Campaign :Advert
getName
listCampaigns
loop (1, *) [i<=campaign.count ]
getCampaignDetails
checkCampaignBudget
loop (1, *) [j<=advert.count ]
getCost
Interaction Operator
with parameters getOverheads
29
sd Add a new advert to a campaign if within budget
:CampaignManager
:Client :Campaign :Advert
getName
listCampaigns
ref
List client campaigns
ref
Get campaign budget
addCostedAdvert
alt [totalCost <= budget]
Advert newAd:Advert
alt interaction operator
shows branching
[else]
Request newRequest:Request
Two interaction
operands, one for each
alternative
30
handling complexity
ref interaction operator
indicates interaction
sd Check campaign budget occurrence that
references an
interaction fragment
:CampaignManager
:Client :Campaign :Advert
getName
listCampaigns ref
Gate showing the List client campaigns
message enter this
interaction occurrence
ref
Get campaign budget
31
Interaction fragment that is
referenced in
Check campaign budget
sequence diagram
sd List client campaigns
Gate showing the
message enter this
Interaction Fragment :Client :Campaign
listCampaigns
loop [For all client’s campaigns]
getCampaignDetails
32
Interaction fragment that is
also referenced in
Check campaign budget
sd Get campaign budget
sequence diagram
:CampaignManager :Campaign :Advert
checkCampaignBudget
loop [For all campaign’s adverts]
getCost
getOverheads
33
sd Add a new advert to a campaign
:ClientCampaigns
:CampaignManager :AddAdvert ref ClientCampaignAds
loop [For all clients]
getClient
:AddAdvertUI
startInterface
selectClient showClientCampaigns listCampaigns
Lifeline representing
the interaction between
selectCampaign showCampaignAdverts
a group of objects
listAdverts
createNewAdvert
addNewAdvert addNewAdvert
34
sd ClientCampaignAds
:Client :Campaign :Advert
getClient
listCampaigns
loop [For all client’s campaigns]
Sequence diagram getCampaignDetails
referenced in the
Add a new advert listAdverts
loop [For all campaign’s adverts]
to a compaign
getAdvertDetails
sequence diagram
addNewAdvert
Advert newAd:Advert
35
sd Authorize expenditure sd Calculate costs
:LifelineA :LifelineB :LifelineC :LifelineA :LifelineB :LifelineC
getCost
ref
Calculate costs getCost
alt [Within budget]
ref
alt [Within budget] Identify under spend
Within budget
Within budget
authorize
[else] [else]
Budget spent Budget spent
stopExpenditure
Continuations are used to link
sequence diagrams
36
sd Interaction Name
An active :ClassA :ClassB
object
t = now Asynchronous
Time message with
constraint duration
using constraint
construction
marks
{t..t + 28}
Callback
Duration
observation
{d..d*3}
Note explaining some
Duration aspect of this
constraint execution occurrence
37
Interaction Explanation and use
Operator
alt Alternatives represents alternative behaviours, each choice of behaviour being shown
in a separate operand. The operand whose interaction constraint is evaluted as true
executes.
opt Option describes a single choice of operand that will only execute if its interaction
contraint evaluates as true.
break Break indicates that the combined fragment is performed instead of the remainder of
the enclosing interaction fragment.
par Parallel indicates that the execution operands in the combined fragment may be
merged in any sequence once the event sequence in each operand is preserved.
seq Weak Sequencing results in the ordering of each operand being maintained but event
occurrence from different operands on different lifelines may occur in any order. The
order of event occurrences on common operands is the same as the order of the
operands.
strict Strict Sequencing imposes a strict sequence on execution of the operands but does
not apply to nested fragments.
neg Negative describes an operand that is invalid.
critical Critical Region imposes a constraint on the operand that none of its event
occurrences on the lifelines in the region can be interleaved.
ignore Ignore indicates the message types, specified as parameters, that should be ignored in
the interaction.
consider Consider states which messages should be consider in the interaction. This is
equivalent to stating that all others should be ignored.
assert Assertion states that the sequence of messaging in the operand is the only valid
continuation.
loop Loop is used to indicate an operand that is repeated a number times until the
interaction constraint for the loop is no longer true.
38
sd Add a new advert to a campaign if within budget
sd List Campaigns for Client
:CampaignManag
:Client :Campaign
er getName
listCampaigns
loop [For all client’s campaigns]
getCampaignDetails
Initial node
ref
Get campaign budget
Interaction occurrence In-line sequence
sd Add costed advert diagram
:CampaignManag :Campaign
er
addCostedAdvert
Decision
[totalCost <= budget] [totalCost > budget]
ref ref
Create advert Create request
Final node
39
sd Car enters car park
before:WeightSensor :TicketMachine :Barrier after:WeightSensor
activate
Lowered
Active
ticketRequested
raiseBarrier
deactivate
Raised
Blocked lowerBarrier
Lowered
barrierLowered
Inactive
40
Sloped line
represents duration
of state change
sd Car enters car park lifelines :Barrier, :TicketMachine
Diagram has two
Timing
instances, one for Raised
Constraint
{t..t+3s}
:Barrier
each lifeline
Lowered
barrierLowered
:TicketMachine
Blocked
raiseBarrier
Active
Message from one
lifeline to another Inactive
41