design-patterns/behavioral/state/concrete_states.py
Ruidy 1694f453ee
State (#21)
* add documentation

* add code example
2020-10-07 17:32:45 +02:00

25 lines
776 B
Python

"""
Concrete States implement various behaviors, associated with a state of the
Context.
"""
from behavioral.state.state import State
class ConcreteStateA(State):
def handle1(self) -> None:
print("ConcreteStateA handles request1.")
print("ConcreteStateA wants to change the state of the context.")
self.context.transition_to(ConcreteStateB())
def handle2(self) -> None:
print("ConcreteStateA handles request2.")
class ConcreteStateB(State):
def handle1(self) -> None:
print("ConcreteStateB handles request1.")
def handle2(self) -> None:
print("ConcreteStateB handles request2.")
print("ConcreteStateB wants to change the state of the context.")
self.context.transition_to(ConcreteStateA())