O'Reilly logo

Python: Master the Art of Design Patterns by Sakis Kasampalis, Chetan Giridhar, Dusty Phillips

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required