Skip to main content

Strategy

When we use it ?

when we have a lot of classes that have the same behavior but each class will execute/implement it in a different way (sometimes some of these classes may have the same one)

when we have an algorithm that could have a more than a version (Example : sort algo : as we know each sort algo is good for a specific input based on its size and many others.. , so we will let our classe decide wich algo to use based on its input :D)

when the algorithm use data that client should not know

Diagram

Strategy%202fa8e244a3264c7daba35b15442345b1/Untitled.png

Example

Strategy%202fa8e244a3264c7daba35b15442345b1/Untitled%201.png