A snack vending machine is an example of the State pattern in everyday life. Vending machines have different states and react differently depending on the amount of money that we insert. Depending on our selection and the money we insert, the machine can do the following:
- Reject our selection because the product we requested is out of stock
- Reject our selection because the amount of money we inserted was not sufficient
- Deliver the product and give no change because we inserted the exact amount
- Deliver the product and return the change
There are, for sure, more possible states, but you get the point.
In the software category, we can think of the following examples:
- 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...