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

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

28 lines
692 B
Python

from abc import ABC, abstractmethod
from behavioral.state.context import Context
class State(ABC):
"""
The base State class declares methods that all Concrete State should
implement and also provides a backreference to the Context object,
associated with the State. This backreference can be used by States to
transition the Context to another State.
"""
@property
def context(self) -> Context:
return self._context
@context.setter
def context(self, context: Context) -> None:
self._context = context
@abstractmethod
def handle1(self) -> None:
pass
@abstractmethod
def handle2(self) -> None:
pass