Software Requirements Engineering Structural & Behavioural Modelling
Software Requirements Engineering Structural & Behavioural Modelling
Requirements Engineering
Lecture 22
STRUCTURAL & BEHAVIOURAL MODELLING
SESD-2213
FALL 2020
Several formal definitions as well as textual and graphical syntax of state machines exist
We focus on the state machines of UML 2.x
Several techniques and tools exist for defining, analyzing, combining, and transforming (e.g., to code) state
machines
5 Automaton
A machine whose output depends not only on the input but also on the history of past events
Its internal state characterizes on
this history
Lamp On
on
ON ON
ON ON
off
OFFOFF
OFF OFF off
Lamp Off
6 Basic Notational Elements of State Machine Diagrams
Describe the dynamic behavior of an individual object (with states and transitions)
7 Types of State Machines
on on
Lamp On
Lamp On print(”on”)
on/print(”on”) on
off off
off off
Lamp Lamp
Off Off
on/ctr := ctr + 1
off
off
Lamp Off
9 Modeling Behavior
In general, state machines are suitable for describing reactive systems based or events
Not appropriate to describe continuous systems (e.g., spacecraft trajectory control, stock market predictions)
threshold
time
10
UML State Machine Diagrams – Summary
Composite State
State
Initial
Initial
Pseudostate
Pseudostate top
Trigger
Trigger
Ready
Transition
Transition
stop /ctr := 0
Done
Final State Action
Action
stop
11 Entry and Exit Actions
LampOn
e2
entry/lamp.on();
exit/lamp.off();
e1
12 Action Ordering
LampOn LampOff
off/printf(“to off”);
entry/lamp.on(); entry/lamp.off();
exit/printf(“exiting”); exit/printf(“exiting”);
“do” activity
Error
entry/printf(“error!”)
do/alarm.ring()
14 Guards (Conditions)
Conditional execution of transitions
bid [value < 100] /reject
Unhappy
LampOff
flash/ LampFlashing
entry/lamp.off()
FlashOn
FlashOn
off/ entry/lamp.on()
1sec/
on/ 1sec/
on/
FlashOff
LampOn
on/
entry/lamp.off()
entry/lamp.on()
16
Group Transitions
Default
Default transition to
Initial
Initial pseudostate
pseudostate
LampOff
flash/ LampFlashing
entry/lamp.off()
FlashOn
off/ entry/lamp.on()
1sec/
on/ 1sec/
FlashOff
LampOn
on/
entry/lamp.off()
entry/lamp.on()
Group transition
17 Completion Transition
Triggered by a completion event
Automatically generated when an embedded state machine terminates
Completion transition
Committing (without trigger)
Phase1
Phase1
CommitDone
Phase2
Phase2
18 Triggering Rules
Many transitions can share the same triggering event
When leaving, the most deeply embedded one takes precedence
The event disappears whether it triggers a transition or not
LampFlashing
FlashOn
on/
off/
on/
FlashOff
19 Action Ordering – Composite States
S1 S2
exit/exS1 entry/enS2
/initS2
S11 E/actE S21
exit/exS11 entry/enS21
What should be added to this state machine to more fully describe the dialing behavior?
21 “Reusable” State Machines (1)
ReadAmountSM
abort
otherAmount definition
selectAmount
of
exit point
amount
abort
EnterAmount
aborted
definition
of
ok
entry point
again
22 “Reusable” State Machines (2)
ATM
VerifyCard
use of
acceptCard exit
point
outOfService ReadAmount : aborted
OutOfService ReadAmountSM
again
use of rejectTransaction
entry point releaseCard
VerifyTransaction ReleaseCard
age
financialStatus
Child
Poor
Adult
age financialStatus
Child Rich
Retiree
Poor
Adult
Retiree Rich
26 Semantics of Orthogonal Regions
All mutually orthogonal regions detect the same events and respond simultaneously (possibly interleaved)
legalStatus financialStatus
LawAbiding
LawAbiding Poor
robBank/ robBank/
Outlaw Rich
27 Interactions Between Regions
Typically through shared variables
sane
sane :: Boolean
Boolean
flying
flying :: Boolean
Boolean
Catch22
Catch22
sanityStatus flightStatus
Crazy Flying
Flying
entry/sane
entry/sane :=
:= false;
false; entry/flying
entry/flying :=
:= true;
true;
(flying)/ (sane)/
request
Grounding/ (~sane)/
Sane Grounded
Grounded
entry/sane
entry/sane :=
:= true;
true; entry/flying
entry/flying :=
:= false;
false;
28 Exercise II – Describe this Behaviour
CourseAttempt
Studying
project done
Term Project
ATM Behaviour
Statemachine
acceptCard()
outOfService()
amount()
FlexibleATM Behaviour
Statemachine
otherAmount()
rejectTransaction()
30 State Machine Inheritance – ATM
ATM
VerifyCard
{final}
acceptCard
OutOfService outOfService
ReadAmount
{final}
releaseCard
VerifyTransaction ReleaseCard
{final} {final}
31 State Machine Inheritance – Flexible ATM
States can be added and extended
FlexibleATM {extended}
Regions can be added and extended
Transitions can be added or extended ReadAmount {extended}
Door {protocol}
[doorWay.isEmpty()] close/
opened closed
create/
open/ lock/
unlock/
locked
33 Protocol State Machine -Pre/Postconditions
Choice
Req(Id)
Action [ID<=10]
[ID>10]
Sequence
MinorReq=Id; MajorReq=Id; Output
Minor(Id) Major(Id)
Busy
State Machine-Based Analysis
36 State Machine-Based Analysis (1)
Several possible alternatives which depend on the formalisms and tools
Simulation
Let the behavior evolve more or less randomly
Can be interactive
Test
Verify that certain traces are supported (or rejected) by the machine
Reachability analysis
All states can be reached and all transitions can be traversed
No unhandled event in each state
Absence of deadlocks (in communicating state machines)
37 State Machine-Based Analysis (2)
Conformance checking
Between two machines (for example, one abstract and the other one more concrete)
Reduce non-determinism
Reduce optional behavior (compliant, but some behaviors are not supported)
Extension (consistent, but some new events are treated and lead to new behaviors)
Equivalence checking
Between two machines (for example, one abstract and the other one more concrete)
Several levels of equivalence: traces, refusals, tests, observational equivalence...
38 State Machine-Based Analysis (3)
Model checking
Verifies that the model satisfies temporal logic
properties, for example:
If A occurs, B could possibly occur
If C occurs, D always occurs
Model checker verifies M P (if not a trace of states and transitions leading to the violation of P is produced)
Major obstacle is state explosion
Theorem proving
Prove by deduction or other formal approaches some properties of the state machine - tools often allow interactive
proving