Has any of you ever seen a
variable, object property or
database field named
status, state or similar?
Let's introduce the
problem first:
Slide 6
Slide 6 text
Let’s write some code…
Slide 7
Slide 7 text
The problem:
We don't control how
state changes!
Slide 8
Slide 8 text
What is state?
Slide 9
Slide 9 text
"The particular
condition that someone
or something is in at a
specific time."
(Oxford Dictionaries)
Slide 10
Slide 10 text
"The particular
condition that someone
or something is in at a
specific time."
(Oxford Dictionaries)
Slide 11
Slide 11 text
State
is a function of
time !
Slide 12
Slide 12 text
S1
S6
S2
S5
Time Set of possible states
t1
t2
t3
t4
t5
t6
t7
S4
S3
Slide 13
Slide 13 text
S1
S6
S2
S5
Time Set of possible states
t1
t2
t3
t4
t5
t6
t7
S4
S3
Slide 14
Slide 14 text
S1
S6
S2
S5
Time Set of possible states
t1
t2
t3
t4
t5
t6
t7
S4
S3
Slide 15
Slide 15 text
S1
S6
S2
S5
Time Set of possible states
t1
t2
t3
t4
t5
t6
t7
S4
S3
Slide 16
Slide 16 text
S1
S6
S2
S5
Time Set of possible states
t1
t2
t3
t4
t5
t6
t7
S4
S3
Slide 17
Slide 17 text
S1
S6
S2
S5
Time Set of possible states
t1
t2
t3
t4
t5
t6
t7
S4
S3
Slide 18
Slide 18 text
S1
S6
S2
S5
Time Set of possible states
t1
t2
t3
t4
t5
t6
t7
S4
S3
Slide 19
Slide 19 text
S1
S6
S2
S5
Time Set of possible states
t1
t2
t3
t4
t5
t6
t7
S4
S3
Slide 20
Slide 20 text
Claim:
Much grief in software development
arises from the inability to control
state, i.e. from uncontrolled mutation
of state.
Slide 21
Slide 21 text
Claim:
Much grief in software development
arises from the inability to control
state, i.e. from uncontrolled mutation
of state.
Proof:
What do we do when we step through
a program to debug a problem?
We pause time to observe state.
Slide 22
Slide 22 text
Finite state machines (FSM)
can help us bringing state
changes under control.
Slide 23
Slide 23 text
FSMs define how we can move
between states ie. what is a valid
move and what is an invalid move.
Slide 24
Slide 24 text
Without a FSM in place, every move
can be seen as a valid move!
Slide 25
Slide 25 text
Arrows between states represent
events/actions.
Slide 26
Slide 26 text
So how do we move between states?
Slide 27
Slide 27 text
So how do we move between states?
The next state is a function of the
current state and the event.
Slide 28
Slide 28 text
So how do we move between states?
The next state is a function of the
current state and the event.
(State, Event) ! State
Slide 29
Slide 29 text
The next state is a function of the
current state and the event.
(State, Event) ! State
This is called the transition function.
So how do we move between states?