www.wileyeurope .com/college/van lamsweerde Chap.13: Modeling System Behaviours © 2009 John Wiley and Sons
Building System Models for RE
Building System Models for RE
Chapter 13
Modeling System Behaviours
www.wileyeurope .com/college/van lamsweerde Chap.13: Modeling System Behaviours © 2009 John Wiley and Sons 2
Building models for RE
Behaviors -
Behaviors -
Scenarios
Scenarios (Chap.13)
Behaviors -
Behaviors -
State machines
State machines (Chap.13)
www.wileyeurope .com/college/van lamsweerde Chap.13: Modeling System Behaviours © 2009 John Wiley and Sons 3
The behaviour model
Behaviour view of the system being modeled
–
Modelling the dynamic of an agent, consider:
Modelling the dynamic of an agent, consider:
Specific behaviours of specific agent instances
All possible behaviours of any agent instance.
Specific instance behaviours are captured through scenarios.
General class behaviours are captured through state machines.
www.wileyeurope .com/college/van lamsweerde Chap.13: Modeling System Behaviours © 2009 John Wiley and Sons 4
Modeling system behaviours: outline
Modeling instance behaviours
– Scenarios as UML sequence diagrams
– Scenario refinement
Modeling class behaviours
–
State machines as UML state diagrams
–
State machine refinement
Building behaviour models
www.wileyeurope .com/college/van lamsweerde Chap.13: Modeling System Behaviours © 2009 John Wiley and Sons 5
Modeling instance behaviours
What is scenario?
What is scenario?
–
Is a temporal sequence of interaction events among agent instances
–
Positive scenario:
Positive scenario: the sequence of interactions illustrates a possible
way of satisfying an behavioural goal.
–
Negative scenario:
Negative scenario: the sequence of interactions illustrates a possible
way of satisfying an obstacle to a goal.
Interaction
Interaction:
– Is an instantaneous object
–
Corresponding to the source agent instance applying an
operation whose effect is monitored by the target agent
instance.
–
Source agent controls the interaction; target agent monitors it.
www.wileyeurope .com/college/van lamsweerde Chap.13: Modeling System Behaviours © 2009 John Wiley and Sons 6
Scenario as UML sequence diagrams
Sequence diagrams are a UML variant of the event trace diag.
Basic UML syntax for sequence diagrams is similar to the one used in
event trace diagrams.
Figure 13.1 – Scenario represented by a sequence diagram
: Train
Actuator/Sensor
: OnBoard
Controller
doorsOpening
exit
doorsClosing
p1: Passenger
entrance
p2: Passenger
software agent
instance
environment agent
time
interaction
event name
! trainStopped
startAcceler
www.wileyeurope .com/college/van lamsweerde Chap.13: Modeling System Behaviours © 2009 John Wiley and Sons 7
Scenario as UML sequence diagrams (2)
Figure 13.2 – Sequence diagram for a loan scenario
: LoanManager
BookRequest (PatrID, BookID)
: Staff
self-interaction
event attributes
instance disappears
: CopyManager
LoanQtyOK? (PatrID)
CpyAvailable? (BookID)
Reserved? (BookID)
OK-Available (CopyID)
OK-Book (PatrID, CopyID)
checkOut (PatrID, CopyID)
Registered? (PatrID)
Figure 13.3 – Negative scenarios and optional interactions
opt
: Train
Actuator/Sensor
: OnBoard
Controller
AlarmPressing
AccelerComnd
doorsOpening
prohibited
interaction
neg
: Train
Actuator/Sensor
doorsOpening
exit
doorsClosing
:Passenger
optional
interaction
: Passenger
: OnBoard
Controller
! trainStopped
startAcceler
AlarmPropagation
www.wileyeurope .com/college/van lamsweerde Chap.13: Modeling System Behaviours © 2009 John Wiley and Sons 8
Scenario refinement: Episodes and agent
decomposition
When elaborating complex scenarios stepwise, expressing a
When elaborating complex scenarios stepwise, expressing a
coarse-grained scenario first then refine it with further details
coarse-grained scenario first then refine it with further details
coarse-grained scenario -> finer-grained scenario:
coarse-grained scenario -> finer-grained scenario:
–
Introducing episodes
Introducing episodes
–
Decomposing an agent instance into finer-grained agents.
Decomposing an agent instance into finer-grained agents.
www.wileyeurope .com/college/van lamsweerde Chap.13: Modeling System Behaviours © 2009 John Wiley and Sons 9
Scenario refinement: Episodes
Figure 13.4 – Scenario refinement: introducing episodes
:Scheduler
meetingRequest
(dateRange, withWhom)
: Initiator
reference to
another
diagram
: Participant
schedule
Determination
ConstraintsAcquired
notification
(date, location)
notification
(date, location)
:Scheduler
? constraints
(dateRange)
: Participant
OK-constr
! constraints
sd ConstraintsAcquired
episode
OK-request
www.wileyeurope .com/college/van lamsweerde Chap.13: Modeling System Behaviours © 2009 John Wiley and Sons 10
Scenario refinement: agent decomposition
Figure 13.5 – Scenario refinement: agent decomposition
: LibraryManager
BookRequest
(PatrID, BookID)
: Staff
RequestOK?
(PatrID, BookID)
OK-Book
(PatrID, CopyID)
: LoanManager
: Staff
: CopyManager
CpyAvailable? (BookID)
Reserved?
(BookID)
OK-Available (CopyID)
checkOut (PatrID,CopyID)
BookRequest
(PatrID, BookID)
OK-Book
(PatrIDCopyID)
LoanQtyOK? (PatrID)
Registered? (PatrID)
www.wileyeurope .com/college/van lamsweerde Chap.13: Modeling System Behaviours © 2009 John Wiley and Sons 11
Modeling system behaviours: outline
Modeling instance behaviours
– Scenarios as UML sequence diagrams
– Scenario refinement
Modeling class behaviours
–
State machines as UML state diagrams
–
State machine refinement
Building behaviour models
www.wileyeurope .com/college/van lamsweerde Chap.13: Modeling System Behaviours © 2009 John Wiley and Sons 12
Modeling class behaviours
State machines complement the fragmentary information
provided by scenarios in multiple ways:
– They make state information explicit
–
They capture the behaviour of any agent instance, not just a
specific one.
–
They are aimed at capturing all admissible sequences of
state transitions, not just a specific one.
Snapshot state <-> SM state
State transitions captured by a state machine refer to SM states.
The events causing state transitions can be of different types:
–
External events: the agent associated with the State Machine
does not controls.
–
Internal events: events controlled by the agent associated with
the State Machine
www.wileyeurope .com/college/van lamsweerde Chap.13: Modeling System Behaviours © 2009 John Wiley and Sons 13
State machines as UML state diagrams
A state machine is represented in UML by a variant of a statechart
called a state diagram.
Some features …
–
State transition is caused by an event
–
Transition may be labeled by the name of the causing event
– In contrast to events, a state has a duration.
–
Initial and final states
Figure 13.6 – A simple SM diagram for a BookCopyInfo entity controlled by LibraryManager
Available
onLoan
checkOut
(PatrID, self)
return
(PatrID, self)
event with
attribute
loss
SM state
initial state
final state
transition
www.wileyeurope .com/college/van lamsweerde Chap.13: Modeling System Behaviours © 2009 John Wiley and Sons 14
State machines as UML state diagrams (2)
Guarded transitions
–
A guard captures a necessary condition for transition firing
Actions
–
An action is an auxiliary associated with a state transition.
Event notifications
–
An important class of action where an event is notified by a
‘producing’ diagram to a ‘consuming’ diagram where this
event causes transitions.
– This allows for synchronization among multiple diagrams.
Entry/exit actions
www.wileyeurope .com/college/van lamsweerde Chap.13: Modeling System Behaviours © 2009 John Wiley and Sons 15
State machines as UML state diagrams (3)
Figure 13.7 – A SM diagram for a BookInfo entity controlled by LibraryManager
Borrowable
UnBorrowable
copyBorrowing
[not LastCopy ]
copyReturn
copyBorrowing
[ LastCopy ]
guard
copyReturn
Figure 13.8 – Auxiliary actions in a state diagram
doorsClosed
doorsOpen
doorsOpening
doorsClosing
[Speed = 0 and AtPlatform]
/ Display terminalInfo
/ Activate warningRinging
action
www.wileyeurope .com/college/van lamsweerde Chap.13: Modeling System Behaviours © 2009 John Wiley and Sons 16
State machines as UML state diagrams (4)
Figure 13.9 – Send actions for diagram synchronization: BookCopyInfo revisited
Available
onLoan
checkOut
(PatrID, self)
return
(PatrID, self)
event
notification
to consumer
loss
/ send BookInfo.copyReturn
/ send BookInfo.copyBorrowing
Figure 13.10 – Avoiding duplicated actions: entry and exit actions within a state
OK-request
/ Inform initiator
…
ConstraintsRequested
entry / Inform initiator
Planning
Resolving
[all available]
[conflicts]
weakeningRequest
/ Inform initiator
ValidatingMeetingData
…
entry
action
www.wileyeurope .com/college/van lamsweerde Chap.13: Modeling System Behaviours © 2009 John Wiley and Sons 17
State machine refinement: sequential and concurrent
sub-states
… when we elaborate a complex state machine model stepwise:
– specify first a coarse-grained state diagram
–
refine this diagram with more states that are finer-grained
– Sub-state -> nested state / super-state -> composite state
Sequential decomposition
–
An SM state may be decomposed into sub-states
– Structuring mechanism is recursive
–
Sub-state my in turn be sequentially decomposed
Parallel decomposition
–
An SM state may be decomposed into concurrent sub-states
–
Composite state can be structured as a parallel composition
of nested diagrams.
www.wileyeurope .com/college/van lamsweerde Chap.13: Modeling System Behaviours © 2009 John Wiley and Sons 18
State machine refinement: sequential decomposition
Figure 13.11 – Sequential state decomposition for the TrainInfo entity controlled by TrainController
Stopped
Moving
include / movingSubstates
[Speed = 0]
Accelerating
Decelerating
(a)
AccelerComnd
[Acceler
≤
0]
movingSubstates
[Acceler
>
0]
AccelerCommand
AccelerComnd
[Acceler
>
0]
AccelerComnd
[Acceler
≤
0]
startAcceler
[Acceler
>
0]
Stopped
[Speed = 0]
startAcceler
[Acceler
>
0]
AccelerComnd
[Acceler
>
0]
Moving
Accelerating
Decelerating
AccelerComnd
[Acceler
≤
0]
AccelerComnd
[Acceler
≤
0]
AccelerComnd
[Acceler
>
0]
(b)
reference
sequential substate
initial substate
Semantic rules define sequential state decomposition more precisely:
[textbook, p459)
www.wileyeurope .com/college/van lamsweerde Chap.13: Modeling System Behaviours © 2009 John Wiley and Sons 19
State machine refinement: parallel decomposition
Semantic rules define parallel state decomposition more precisely:
[textbook, p461)
Figure 13.12 – Parallel state decomposition and hierarchical state machines
TrainInfoState
DoorsState
MovementState
parallel
composition
state name
composite state
Stopped
[Speed = 0]
startAcceler
[doorsState = closed]
AccelerComnd
[Acceler
>
0]
Moving
Accelerating
Decelerating
AccelerComnd
[Acceler
≤
0]
AccelerComnd
[Acceler
≤
0]
AccelerComnd
[Acceler
>
0]
doorsClosed
doorsOpen
[Speed = 0 and AtPlatform]
doorsOpening
/ Display terminalInfo
doorsClosing
/ Activate warningRinging
TrainInfoState
DoorsState
MovementState
sequential
substate
concurrent
substate
guard as
synchronizing
condition
+ sequential
decomposition
www.wileyeurope .com/college/van lamsweerde Chap.13: Modeling System Behaviours © 2009 John Wiley and Sons 20
Modeling system behaviours: outline
Modeling instance behaviours
– Scenarios as UML sequence diagrams
– Scenario refinement
Modeling class behaviours
–
State machines as UML state diagrams
–
State machine refinement
Building behaviour models
www.wileyeurope .com/college/van lamsweerde Chap.13: Modeling System Behaviours © 2009 John Wiley and Sons 21
Building behaviour models
Goals, scenarios and state machines have complementary
strengths and limitations:
– Goals are declarative, capture functional, non-functional and
alternative options aspects.
–
Scenarios support an informal, narrative and concrete style
of expression.
–
State machines provide visual abstractions of explicit
behaviours of any agent instance in a class.
Expecting goals, scenarios and state machines to form a win-win
partnership for building complex models.
Table 13.1 summarizes the respective pros/cons of goals,
scenarios and state machines. (textbook.p464).
www.wileyeurope .com/college/van lamsweerde Chap.13: Modeling System Behaviours © 2009 John Wiley and Sons 22
Building behaviour models
Elaborating relevant scenarios for good coverage
Decorating scenarios with state conditions
From scenarios to state machines
From scenarios to goals
From operationalized goals to state machines.