Definition
It is a behavioural pattern that encapsulates each algorithm in a family of algorithms being used in a program. The encapsulation allows the program to chose any of the algorithms without having to modify the code used in the algorithm.
GoF Template
-
Strategy: This is an interface or abstract base class that defines a family of interchangeable algorithms.
-
Concrete Strategies: These are the concrete implementations of the strategies, each providing a specific algorithm.
-
Context: This holds a reference to a strategy object and uses it to perform a certain task. The context can switch between different strategies dynamically.