Communication Diagram - UW

Communication Diagram
Communication diagram
• Also called “Collaboration diagram” in
previous versions of UML
• A part of interaction view that explains
interactions between objects with context
information
– Context in this case is implied by links
(instantiations of associations) and sequences of
message passing
• A communication diagram includes objects
and their interactions
– A subset of objects taken from the class diagram
to illustrate a particular scenario
C-S 446/546
2
Communication diagram –
of
basic syntax Instances
associations
1: Op1 (params)
Obj1 : Class A
: Class B
2 : return
5 : ret := Op3()
3 : stimulus
4 : Op2 (params)
Obj2 : Class A
C-S 446/546
3
Communication diagram semantics
• Objects and links (instances of associations)
are chosen from the class diagram
• Messages, stimuli and return arrows are
drawn parallel to the links, with each
message/stimulus having a unique label
– Generally, numeric labels are preferred to show
the ordering of these message communications
• There can be as many messages, stimuli and
return arrows on top of a link but their labels
indicate when these communications take
place
C-S 446/546
4
Communication diagram –
semantics (continued)
• The return value for a message can be
shown
– on a separate return arrow (see the return
arrow labeled ‘2’) or
– on the message itself (see the message arrow
labeled ‘5’)
• the return value in this case is filled after the
message communication is completed
• Labels for interactions can be chosen as
1,2,3,… or 1, 1.1, 1.1.1, 1.2, 1.2.1, 1.3, …
C-S 446/546
5
Conditions and iterations syntax
1: *[x=1..10] Op1 (x)
Obj1 : Class A
: Class B
2 : return
5 : ret := Op3()
3:
[condition]
stimulus
4 : [for each x] Op2 (x)
condition
iteration
Obj2 : Class A
C-S 446/546
6
Conditions and iterations semantics
• When an iteration is specified in a
message/stimulus, the message/stimulus is
repeated as many times as indicated in the
iteration
– All the subordinate messages/stimuli are also
exercised in the iteration
– Example: iteration specified on a message labeled
‘4’. This indicates iterations on ‘4’, ‘4.1’, ‘4.1.1’,
‘4.2’ until the next label ‘5’ is seen
• Conditions may specify timing relationships
C-S 446/546
7
2.1.1: result :=
checkPrereqs(prereqs)
:Student
1: confirm := isSeatAvailable()
5 : change := pay (student#, course#, amount)
2:request := register (student#, prereqs)
:Registrar
:Course
2.1: confirm :=
registerThis (student#,
prereqs)
2.1.2: [result = true]
updateEnrolment(student#)
4: requestPayment (student#, course#, amount)
:Account
3: [confirm = true] initiatePayment
(student#, course#)
Course registration system – registration scenario
C-S 446/546
8
Scenario: ATM Transactions – Deposit, Withdraw Normal
5: finishTransactions()
4: [amt2 <= balance] withdraw (amt2)
3: deposit (amt1)
2: amt := returnBalance ()
4.1: decrease balance
(amt2)
3.1: increase balance
(amt1)
: Account
{new}{destroy}
: Customer
1: confirm := retrieve (act#)
: Accounts
Database
1.1 : Account (act#,bal)
{new}
5.1 : updateAccount
(act#, balance)
5.2 : ~Account (act#) {destroy}
C-S 446/546
9
Observations
• The keyword “{new}” shown on an object
indicates that the object is created during this
scenario
• The keyword “{destroy}” shown on an object
indicates that the object is destroyed during this
scenario
• The keyword “{new}” shown on a message /
stimulus indicates that this message / stimulus is
responsible for creating the object
• The keyword “{destroy}” shown on a message /
stimulus indicates that this message / stimulus is
responsible to destroy the object
C-S 446/546
10
Exercise
• Draw the communication diagram for
– Inventory example
– Job posting example
C-S 446/546
11