The Strategy Pattern

The strategy pattern allows you to change the behavior of a class during run-time. 

This pattern is used whenever a class needs to exhibit variant behavior depending on the state of an object that may has been changed by user interaction, per example.

The implementation of the strategy

For strategy we need to implement a interface for the behavior that will changes in run-time.  

After the interface it's necessary to implement the concretes classes with the desired behaviors.

And finally a class using the strategy to change the behavior in run-time.

The way the strategies are selected is an implementation detail, it does not alter the effect of the pattern.

Main photo by O12 at Unsplash.

Thank you for reading and if you have a question use the comments!

Best regards,
Daniel Maurer