LLD 2- Strategy Design Pattern

Q1) what is the design pattern

Ans: Design Patterns are the typical solutions to commonly occurring problems in software design. They are like pre-made blueprints that you can customize to solve a recurring design problem in your code. using these object-oriented programming principles we design manageable, scalable, reusable software.

Q2) where to use Strategy Design Pattern

Ans: children having the same type of capability which was earlier overridden from the base class will create duplicate code which is not reusable anymore. in this case, we think of creating different strategies for different capabilities hence Strategy Design Pattern comes into the picture.

Example

without using Strategy Design Pattern

UML Class Diagram

Code

Using Strategy Pattern

UML Class Diagram

Code

Leave a Comment