The Strategy pattern?
The Strategy pattern represents a pattern that deals with encapsulating modified algorithms in an interface and making them interchangeable. This means you have an interface that represents a specific process or business case and you interchange concrete implementations at runtime so that you can change its behavior.
This pattern conceptually represents the simplest abstraction because it's essentially an interface that accepts different implementors at runtime. The only complexity you need to consider is how and when to switch between the strategies depending on the current context.
We will explain when to use this pattern next.
When to use the Strategy pattern
You can use the Strategy pattern whenever you see the following patterns:
- You have different variants of an algorithm and you want to interchange them at runtime: The variants of the algorithm might try different paths or conditions and you want the application to be able to switch...