Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
When multiple behaviors are needed in a class, we typically use multiple conditional statements in its operations. Instead of many conditionals, move relates conditional behaviors into their own Strategy class.
This pattern helps implement one of the basic principles of Object Oriented programming, i.e. Open Close Principle. This principle states classes should be open for extension but closed for modification. It implies "change" what the modules do without changing them.
View & Download:
To view the entire Strategy Pattern, please login with your Verification Academy Full Access account.