Implementation

Let's write the required Python 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 derived ConcreteState classes, where each derived class contains only the state-specific required functionality. A sample implementation can be found at [j.mp/statepat]. 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 ...

Get Python: Master the Art of Design Patterns now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.