Book Image

Mastering Python Design Patterns

By : Sakis Kasampalis
Book Image

Mastering Python Design Patterns

By: Sakis Kasampalis

Overview of this book

Table of Contents (23 chapters)
Mastering Python Design Patterns
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
The Factory Pattern
Index

A software example


Using the State pattern in essence means implementing a state machine to solve a software problem in a specific domain. The django-fsm package is a third-party package that can be used to simplify the implementation and usage of state machines in the Django framework [j.mp/django-fsm].

Python offers more than one third-party package/module to use and implement state machines [j.mp/pyfsm]. We will see how to use one of them in the implementation section.

Another project worth mentioning is the State Machine Compiler (SMC). With SMC, you can describe your state machine in a single text file using a simple Domain Specific Language (DSL), and it will generate the state machine's code automatically. The project claims that the DSL is so simple that you can write it as a one-to-one translation of a state diagram. I haven't tried it but that sounds very interesting. SMC can generate code in a number of programming languages, including Python [j.mp/smcsrc].