@@ -0,0 +1,1149 @@
+#%0A# Python Design Patterns: State%0A# Author: Jakub Vojvoda %5Bgithub.com/JakubVojvoda%5D%0A# 2016%0A#%0A# Source code is licensed under MIT License%0A# (for more details see LICENSE)%0A# %0A%0Aimport sys%0A%0A#%0A# State%0A# defines an interface for encapsulating the behavior associated%0A# with a particular state of the Context%0A#%0Aclass State:%0A  def handle(self):%0A    pass%0A%0A#%0A# Concrete States%0A# each subclass implements a behavior associated with a state%0A# of the Context%0A#%0Aclass ConcreteStateA(State):%0A  def __init__(self):%0A    State.__init__(self)  %0A  %0A  def handle(self):%0A    print(%22State A handled.%22)%0A%0Aclass ConcreteStateB(State):%0A  def __init__(self):%0A    State.__init__(self)  %0A  %0A  def handle(self):%0A    print(%22State B handled.%22)%0A%0A#%0A# Context%0A# defines the interface of interest to clients%0A#%0Aclass Context:%0A  def __init__(self):%0A    self._state = State()%0A    %0A  def setState(self, state):%0A    self._state = state%0A%0A  def request(self):%0A    self._state.handle()%0A%0A%0Aif __name__ == %22__main__%22:%0A  stateA = ConcreteStateA()%0A  stateB = ConcreteStateB()%0A  %0A  context = Context()%0A  %0A  context.setState(stateA)%0A  context.request()%0A%0A  context.setState(stateB)%0A  context.request()%0A

add State pattern