Replace Conditional Logic with Strategy Pattern
The basic principle of object-oriented design patterns is that they should be open for extension and closed for modification. (OCP, Open Closed Principle)
It should be possible to extend or change the functionality of a module without modifying the code.
When we have if-else statment in method and want to modify by adding new functionality the OCP priciple will be violated.
OCP: (Open-Closed Principle). Software entities (classes, modules, functions, etc.) should be open for extension but closed for change.
To solve the problem we can use design pattern.
Comments
Post a Comment