Rahul
1 min readSep 12, 2019

Strategy Pattern

Strategy pattern makes sure that Open close principle of SOLID principle is not violated. Open Closed Principle. Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification. The main idea behind this one is that in one part of your code, you have your abstractions such as classes, modules, higher order functions that do one thing and do it well.

Sorter.java only has sort method

In the sorter manager class we just need to call sorter.sort(); This is a perfect abstraction and this is what strategy pattern is because it does not know

So now if we need to make say QUICKSORT. Now we just need to add a class for quicksort and that’s it.

No responses yet