diff --git a/behavioral/strategy.py b/behavioral/strategy.py index 45b87601..bf008fe9 100644 --- a/behavioral/strategy.py +++ b/behavioral/strategy.py @@ -2,6 +2,24 @@ # -*- coding: utf-8 -*- """ +*What is this pattern about? +This pattern aims to encapsulate each algorithm and allow them to be +interchangeable. Separating algorithms allows the client to scale +with larger and more complex algorithms, since the client and the +strategies are kept independent of each other. + +Having the algorithms as an integral part of the client can cause the +client to be larger and harder to maintain. This is more evident when +supporting multiple algorithms. The separation of client and algorithm +allows us to easily replace and vary the algorithm. + +*What does this example do? +Below the 'StrategyExample' is an example of the client while the two +functions; 'execute_replacement1' and 'execute_replacement2' are +examples of the implementation or strategy. In the example we can see +that the client can vary it's 'execute' method by changing the +strategy which is responsible for implementation. + http://stackoverflow.com/questions/963965/how-is-this-strategy-pattern -written-in-python-the-sample-in-wikipedia In most of other languages Strategy pattern is implemented via creating some