ColinMay80
Member
- Joined
- Sep 27, 2021
- Messages
- 10
- Programming Experience
- 3-5
Im refactoring some legacy code and came across a function which takes in a dictionary and an object to update. The method is in a base class and consists of nested For each loop and a switch with prob 10+ cases. Basically the outer loop iterates through the items and inner loop checks each item key. The switch statement checks for a given property on the passed in object and then updates it with the value in the case statement or calls another method to do it. This is definitely bad design and code smell. Whilst I usually use polymorphism to remove switch statements but I‘m wondering if I should as in this case. This base class method merely updates properties of a passed in object from a dictionary of values. Any suggestions for better OO design and more maintainable code?
thanks
thanks