mirror of
https://github.com/rjNemo/design-patterns
synced 2026-06-06 02:26:40 +00:00
25 lines
776 B
Python
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())
|