mardi 24 avril 2018

Refactor switch to strategy pattern c#

I investigated a lot about refactoring switch to a hierarchy of classes by means of applying strategy pattern. All samples end up with instead of creating switch statement it just creates the dictionary with the same keys as in switch cases and as values it uses new classes for each case. What is the reason for doing this? According to SOLID open-closed principle, we still needed to go to the class with a dictionary and ADD NEW KEY over there simultaneously with adding the new class for type. We anyway forced to edit class with a dictionary, as for me it violates Open close principle Could anyone give me a good example of refactoring switch statement?

Aucun commentaire:

Enregistrer un commentaire