Skip to content

Commit 33acd7a

Browse files
author
GiantsLoveDeathMetal
committed
Add description to the strategy pattern
1 parent d39cab0 commit 33acd7a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

behavioral/strategy.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22
# -*- coding: utf-8 -*-
33

44
"""
5+
*What is this pattern about?
6+
This pattern aims to encapsulate each algorithm and allow them to be
7+
interchangeable. Separating algorithms allows the client to scale
8+
with larger and more complex algorithms, since the client and the
9+
strategies are kept independent of each other.
10+
11+
Having the algorithms as an integral part of the client can cause the
12+
client to be larger and harder to maintain. This is more evident when
13+
supporting multiple algorithms. The separation of client and algorithm
14+
allows us to easily replace and vary the algorithm.
15+
16+
*What does this example do?
17+
Below the 'StrategyExample' is an example of the client while the two
18+
functions; 'execute_replacement1' and 'execute_replacement2' are
19+
examples of the implementation or strategy. In the example we can see
20+
that the client can vary it's 'execute' method by changing the
21+
strategy which is responsible for implementation.
22+
523
http://stackoverflow.com/questions/963965/how-is-this-strategy-pattern
624
-written-in-python-the-sample-in-wikipedia
725
In most of other languages Strategy pattern is implemented via creating some

0 commit comments

Comments
 (0)