-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Mastering Python Design Patterns
By :

Let's write code that demonstrates how to create a state machine based on the state diagram shown earlier in this chapter. Our state machine should cover the different states of a process and the transitions between them.
The State design pattern is usually implemented using a parent State
class that contains the common functionality of all the states, and a number of concrete classes derived from State
, where each derived class contains only the state-specific required functionality. In my opinion, these are implementation details. The State pattern focuses on implementing a state machine. The core parts of a state machine are the states and transitions between the states. It doesn't matter how those parts are implemented.
To avoid reinventing the wheel, we can make use of the existing Python modules that not only help us create state machines, but also do it in a Pythonic way. A module that I find very useful is state_machine
. Before going any further, if state_machine
is...
Change the font size
Change margin width
Change background colour