Skip to content

Commit 1f18544

Browse files
committed
Update README.md
1 parent 163bada commit 1f18544

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,14 @@
207207
##Strategy
208208
**Intent:** Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
209209

210+
![alt text](https://github.com/iluwatar/java-design-patterns/blob/master/strategy/etc/strategy.jpg "Strategy")
211+
212+
**Applicability:** Use the Strategy pattern when
213+
* many related classes differ only in their behavior. Stratefies provide a way to configure a class eith one of many behaviors
214+
* you need different variants of an algorithm. for example, you migh define algorithms reflecting different space/time trade-offs. Strategies can be used when these variants are implemented as a class hierarchy of algorithms
215+
* an algorithm uses data that clients shouldn't know about. Use the Strategy pattern to avoid exposing complex, algorithm-specific data structures
216+
* a class defines many behaviors, and these appear as multiple conditional statements in its operations. Instead of many conditionals, move related conditional branches into their own Strategy class
217+
210218
##Template method
211219
**Intent:** Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.
212220

0 commit comments

Comments
 (0)