Intent
Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
Similar to Template Method, but instead of changing the entire class, this enables an algorithm's behaviour to be selected at run time as an object.
How is this applied?
- For variants of an algorithm.
- For example you might define an algorithms reflecting different space/time-trade offs.
UML diagram representation
https://sourcemaking.com/files/v2/content/patterns/Strategy_example1-2x.png
More to follow...
No comments:
Post a Comment