The point of state machines is to really nail down what something means, and how it works.
However, FSMs have been around for decades, and have been extended by a wide range of people in a wide range of languages. These individuals have used a diversity of language for similar or identical features.
As such, let's start with some basic vocabulary.
state
- The nodes of the graph.
- Here, there are four
state
s:Red
,Green
,Yellow
, andOff
- The finite state machine is always in exactly one
state
. - Other than during hooks, where the past and future state may be validated in parallel, there is no "in-between" or overlap. To the outside world, the transition between states is atomic.
transition
- The edges of the graph.
- Here, there are seven edges, though one may not be obvious:
- Three for the colors' switching:
- From
Red
toGreen
- From
Green
toYellow
- From
Yellow
toRed
- From
- Three for each color turning off:
- From
Green
toOff
- From
Yellow
toOff
- From
Red
toOff
- From
- One for turning the light on
- From
Off
toRed
- this one can be hard to notice, since it's between the same two edges as #6 - it's visible on the graph as a doubled edge
- From
- Three for the colors' switching: