Strategy Design Pattern

Before showing how this pattern works, please look at the code which has issues

https://github.com/pbndru/Phani.ToRefactor

Here in this code you can clearly see there is a tight coupling between services and the controller class

When adding a new service language or removing one required changing SWITCH statements in the controller

Also we need to change the unit tests

Now this code can be changed using Strategy pattern

Code for Stragey Pattern: https://github.com/pbndru/Phani.StrategyPattern

In this code, you can see there is no tight coupling between developer provider classes and controller.

Also when adding or removing provider, i dont need to change anything in this controller code

Changing unit tests will be easy as we dont need to mock providers

When adding new provider, we just need to add new LanguateType enum and

add new provider . Asusual we need to registe the provider using Dependcy Injection

Leave a comment