Strategy Design Pattern Explained

1 min read
Definition:
A family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
Simple Meaning:
Strategy design pattern helps us avoid code duplication by providing us various algorithms/implementations to choose from for a particular abstract method/function or even overriding and all these algorithms are loosely coupled.
What was the problem ?
Let's explore with the help of the following class diagram
image 1
image 2
Solution :
Playground link:
https://excalidraw.com/#json=EBsBZ-2A6VZ5IAl2iAIsU,VxK83jS1s0_SODtODzXhpg
0
Subscribe to my newsletter
Read articles from ROHIT SADHU directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

ROHIT SADHU
ROHIT SADHU
I am fond of problem solving, learning new algorithms and methods to solve problems and also inclined towards development and machine learning.