@@ -0,0 +1,1197 @@
+#%0A# Python Design Patterns: Strategy%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# Strategy%0A# declares an interface common to all supported algorithms%0A#%0Aclass Strategy:%0A  def algorithmInterface(self):%0A    pass%0A%0A#%0A# Concrete Strategies%0A# implement the algorithm using the Strategy interface%0A#%0Aclass ConcreteStrategyA(Strategy):%0A  def __init__(self):%0A    Strategy.__init__(self)%0A  %0A  def algorithmInterface(self):%0A    print(%22Concrete Strategy A%22)%0A%0Aclass ConcreteStrategyB(Strategy):%0A  def __init__(self):%0A    Strategy.__init__(self)%0A  %0A  def algorithmInterface(self):%0A    print(%22Concrete Strategy B%22)%0A%0Aclass ConcreteStrategyC(Strategy):%0A  def __init__(self):%0A    Strategy.__init__(self)%0A  %0A  def algorithmInterface(self):%0A    print(%22Concrete Strategy C%22)%0A%0A#%0A# Context%0A# maintains a reference to a Strategy object%0A#%0Aclass Context:%0A  def __init__(self, strategy):%0A    self._strategy = strategy%0A%0A  def contextInterface(self):%0A    self._strategy.algorithmInterface()%0A%0A%0Aif __name__ == %22__main__%22:%0A  strategy = ConcreteStrategyA()%0A    %0A  context = Context(strategy)%0A  context.contextInterface()%0A

add Strategy pattern