state pattern state pattern on an abstract levelall object-oriented systems concern themselves with the actors in system and how the actions of each impact the other actors and the system as whole this is why state machine is so helpful in modeling the state of an object and the things that cause said object to react in object-oriented systemsthe state pattern is used to encapsulate behavior variations based on the internal state of an object this encapsulation solves the monolithic conditional statement we saw in our previous example this sounds greatbut how would this be accomplishedwhat you need is some sort of representation for the state itself sometimesyou may even want all the states to share some generic functionalitywhich will be coded into the state base class thenyou have to create concrete state class for every discrete state in your state machine each of these can have some sort of handler function to deal with input and cause transition of stateas well as function to complete the action required of that state in the following code snippetwe define an empty base class that the concrete state classes will be inherited from note thatas in previous python' duck-typing system allows you to drop the state class in this most basic implementation include the base class state in the snippet for clarity only the concrete states also lack action methodsas this implementation takes no actionand as such these methods would be empty class state(object)pass class concretestate (state)def __init__(selfstate_machine)self state_machine state_machine def switch_state(self)self state_machine state self state_machine state class concretestate (state)def __init__(selfstate_machine)self state_machine state_machine