Sequence Diagrams Version 020913 Sequence Diagrams are History

advertisement
Sequence Diagrams
Version 020913
INF-UIT 2002 / Basic Sequence Diagrams / Slide 1
Øystein Haugen
Ketil Stølen
Sequence Diagrams
Sequence Diagrams are
–
–
–
–
simple
powerful
readable
used to describe interaction sequences
–
–
–
–
Has been used for a number of years informally
Standardized in 1992 in Z.120 (Message Sequence Charts - MSC)
Last version of MSC is from 1999 (called MSC-2000)
Formal semantics of MSC-96 is given in Z.120 Annex B
History
– Included in UML from 1999, but in a rather simple variant
– Last public suggestion from UML 2 Partners on UML 2.0 can be found
on http://www.u2-partners.org/
INF-UIT 2002 / Basic Sequence Diagrams / Slide 2
Øystein Haugen
Ketil Stølen
Purpose
Emphesizes the interaction between objects indicating that the
interplay is the most important aspect
– Often only a small portion of the total variety of behavior is described
improve the individual understanding of an interaction problem
Sequence Diagrams are used to ...
–
–
–
–
–
document protocol situations,
illustrate behavior situations,
verify interaction properties relative to a specification,
describe test cases,
document simulation traces.
INF-UIT 2002 / Basic Sequence Diagrams / Slide 3
Øystein Haugen
Ketil Stølen
The example context: Dolly Goes To Town
Dolly is going to town and
–
–
–
–
wants to subscribe for bus schedules back home
given her current position
and the time of day.
The service should not come in effect until a given time in the evening
INF-UIT 2002 / Basic Sequence Diagrams / Slide 4
Øystein Haugen
Ketil Stølen
The informal architecture
positioning
web
terminal
position
local
ads
ads
info
subscription
info
subscription
mobile request
terminal
information
provider
info
info
info
local
cache
info
user
information pusher
(SMS sender, WAP portal)
INF-UIT 2002 / Basic Sequence Diagrams / Slide 5
Øystein Haugen
Ketil Stølen
Lifeline (MSC: Instance)
Lifelines
Lifelinesare
arethe
theactors
actorsof
ofan
anInteraction
Interaction
ServiceBase
Lifeline head with name
(ignore the underlining!)
Lifeline
ordered from
top to bottom
INF-UIT 2002 / Basic Sequence Diagrams / Slide 6
Øystein Haugen
Ketil Stølen
(Simple) Sequence Diagram
Messages have one send event, and one receive event.
– The send event must occur before the receive event.
– The send event is the result of an Action
Events are strictly ordered along a lifeline from top to bottom
The frame
(UML 2)
sd Authorization
ServiceUser
ServiceBase
ServiceTerminal
Code()
The name
OK()
OnWeb()
Send Event
OK()
Receive Event
Message name
INF-UIT 2002 / Basic Sequence Diagrams / Slide 7
Øystein Haugen
Ketil Stølen
How many global traces does this diagram show?
The only invariants:
– Messages have one send event, and one receive event. The send event
must occur before the receive event.
– Events are strictly ordered along lifeline
How
Howmany?
many?
•• 1,
1,2,
2,3,
3,4,
4,5,
5,6,..?
6,..?
sd Authorization
ServiceUser
ServiceBase
ServiceTerminal
Code()
OK()
OnWeb()
OK()
independent!
INF-UIT 2002 / Basic Sequence Diagrams / Slide 8
Øystein Haugen
Ketil Stølen
Asynchronous messages: Message Overtaking
asynchronous communication = when the sender does not wait for
the reply of the message sent
Reception is normally interpreted as consumption of the message.
When messages are asynchronous, it is important to be able to
describe message overtaking.
notice
message
to/from
environment
sd Authorization
ServiceBase
ServiceTerminal
Code()
OK()
receiving OnWeb after
receiving Info
Info()
sending OnWeb
before sending Info
OnWeb()
OK()
INF-UIT 2002 / Basic Sequence Diagrams / Slide 9
Øystein Haugen
Ketil Stølen
The context of a Sequence Diagram
The context is a Classifier with Internal Structure (of Parts)
– Parts are represented by Lifelines
– Generic Parts of Collaborations must be bound to concrete Parts
– Concrete Parts of Classes can be Lifelines directly
In MSC (Message Sequence Charts) the context is an “MSC
document”
The concept of a context with internal structure leads to an
aggregate hierarchy of entities (parts)
– We exploit this through the concept of Decomposition
INF-UIT 2002 / Basic Sequence Diagrams / Slide 10
Øystein Haugen
Ketil Stølen
Decomposing a Lifeline relative to an Interaction
sd Authorization
ServiceUser
____ServiceBase_____
ref SB_Authorization
ServiceTerminal
Code()
OK()
OnWeb()
OK()
this is the name of
the diagram where
we find the
decomposition
we want to look
into this lifeline
Øystein Haugen
INF-UIT 2002 / Basic Sequence Diagrams / Slide 11
Ketil Stølen
The Decomposition
sd Authorization
ServiceUser
____ServiceBase_____
ref SB_Authorization
ServiceTerminal
Code()
sd SB_Authorization
OK()
OnWeb()
OK()
Central
Code()
create()
notice the
correspondance!
Authorizer
OKI()
OnWeb()
OK()
notice the
correspondance!
INF-UIT 2002 / Basic Sequence Diagrams / Slide 12
Øystein Haugen
Ketil Stølen
Lifeline creation and destruction
We would like to describe Lifeline creation and destruction
The idea here (though rather far fetched) is that the ServiceBase needs to create
a new process in the big mainframe computer to perform the task of authorizing
the received Code. We see a situation where several Authorizers work in parallel
sd SB_Authorization
creation Message
Central
Code()
destruction
create()
Authorizer
OKI()
OnWeb()
OK()
Øystein Haugen
INF-UIT 2002 / Basic Sequence Diagrams / Slide 13
Ketil Stølen
Synchronizing interaction
method call
message
sd Authorization
method activation
ServiceUser
ServiceBase
ServiceTerminal
Code()
OnWeb()
OnWebConfirm()
CodeOK()
suspension region
(UML 2, MSC2000)
confirm?()
confirmed!()
reply
INF-UIT 2002 / Basic Sequence Diagrams / Slide 14
Øystein Haugen
Ketil Stølen
Basic Sequence Diagrams Summary
We consider mostly messages that are asynchronous, the sending
of one message must come before the corresponding reception
UML has traditionally described synchronizing method calls rather
than asynchronous communication
The events on a lifeline are strictly ordered
The distance between events is not significant.
The context of Interactions are classifiers
A lifeline (within an interaction) may be detailed in a decomposition
Dynamic creation and destruction of lifelines
INF-UIT 2002 / Basic Sequence Diagrams / Slide 15
Øystein Haugen
Ketil Stølen
Achieving more structure (UML 2.0 from MSC-96)
references – such that Interactions may be referenced within other
Interactions
combination – combining Interaction fragments to express
alternatives, parallel merge and loops
better overview of combinations – High level Interactions where
Lifelines and individual Messages are hidden
gates – flexible connection points between references/expressions
and their surroundings
INF-UIT 2002 / Basic Sequence Diagrams / Slide 16
Øystein Haugen
Ketil Stølen
References
sd GoHome
reference
ServiceUser
ServiceBase
ServiceTerminal
ref
GoHomeSetup
loop
ref
GoHomeInvocation
ref
GoHomeDismantle
INF-UIT 2002 / Basic Sequence Diagrams / Slide 17
Øystein Haugen
Ketil Stølen
Combined fragments of Interaction
MSC-96: “inline expressions”
UML 2.0: “combined fragments”
We want to express
– choices: alternative, option, exception
– parallel merge
– loops
We may also want to add other operators
– negation
– critical region
– assertion
Other suggested operators that will not come in UML 2.0
– interrupt
– disrupt
INF-UIT 2002 / Basic Sequence Diagrams / Slide 18
Øystein Haugen
Ketil Stølen
Combination example
sd GoHomeInvocation
frame
ServiceUser
Clock
ServiceBase
ServiceTerminal
InvocationTime()
operator
GiveTransportSchedule()
loop<n>
operand
separator
alt
ScheduleIntervalElapsed()
FindLocation()
TransportSchedule()
GetTransportSchedule()
TransportSchedule()
FetchSchedule()
Schedule()
INF-UIT 2002 / Basic Sequence Diagrams / Slide 19
Øystein Haugen
Ketil Stølen
sd GoHomeSetup
Interaction Overview
ref
activity diagram
Authorization
start
ref
references
flow line
FindLocation
sd
inline diagram
ServiceUser
ServiceBase
SetHome()
sd GoHomeSetup
ServiceUser
ServiceBase
ref
ServiceTerminal
sd
Authorization
opt
ServiceUser
ref
FindLocation
ServiceBase
SetInvocationTime()
SetTransportPreferences()
SetHome()
end
SetInvocationTime()
SetTransportPreferences()
INF-UIT 2002 / Basic Sequence Diagrams / Slide 20
Øystein Haugen
Ketil Stølen
Gates
sd GoHomeSetup
ServiceUser
ServiceBase
Code()
ServiceTerminal
sd Authorization
ref
OK()
Authorization
OK()
ServiceBase
ServiceTerminal
Code()
opt
ref
OK()
FindLocation
SetHome()
Info()
OnWeb()
SetInvocationTime()
OK()
SetTransportPreferences()
formal gate
actual gate
Øystein Haugen
INF-UIT 2002 / Basic Sequence Diagrams / Slide 21
Ketil Stølen
Summary: Dolly Goes To Town (1)
sd GoHomeSetup
sd GoHome
ServiceUser
ServiceBase
ServiceTerminal
ref
Authorization
ref
GoHomeSetup
ref
FindLocation
loop
ref
GoHomeInvocation
sd
ref
ServiceUser
GoHomeDismantle
ServiceBase
SetHome()
sd
Interaction
Reference
ServiceUser
ServiceBase
SetInvocationTime()
SetTransportPreferences()
INF-UIT 2002 / Basic Sequence Diagrams / Slide 22
Øystein Haugen
Ketil Stølen
Interaction
Overview
Diagram
Dolly Goes To Town (2)
sd Authorization
sd Authorization
ServiceUser
ServiceUser
____ServiceBase_____
ref SB_Authorization
ServiceTerminal
ServiceBase
ServiceTerminal
Code()
Code()
OnW eb()
OnW ebConfirm()
OK()
CodeOK()
OnWeb()
confirm?()
OK()
confirmed!()
synchronizing
decomposed
sd SB_Authorization
sd FindLocation
decomposition
Central
Code()
sender
create()
receiver
creation
Authorizer
GiveLocation()
OKI()
OnW eb()
OK()
gate
location()
destruction
Øystein Haugen
INF-UIT 2002 / Basic Sequence Diagrams / Slide 23
Ketil Stølen
Dolly Goes To Town (3)
sd GoHomeInvocation
operator:
loop
ServiceUser
Clock
ServiceBase
ServiceTerminal
InvocationTime()
operator:
choice
GiveTransportSchedule()
loop<n>
operand
separator
alt
ScheduleIntervalElapsed()
FindLocation()
TransportSchedule()
GetTransportSchedule()
TransportSchedule()
FetchSchedule()
Schedule()
INF-UIT 2002 / Basic Sequence Diagrams / Slide 24
Øystein Haugen
Ketil Stølen
Combined
fragment
Download