Kevin told me he found a funny page on a recurring theme in refactoring. As Uncle Bob said in his “Code Smells” when you see a code that have conditionals or too many “ifs”… is that there is something wrong … One of the keys to refactor is to replace the IF by polymorphism.
REFACTORING
When we want to refactor, we should always refactor by design patterns, knowing what we do …
I use to come back to the Martin Fowler RefactoringCatalog
We found that refactoring is an aggressive process which virtually hurts the keyboard exercising all the shortcuts of our IDE.
Specifying the substitution of conditionals
As Fowler says: “When you have a conditional that chooses between different behaviors depending on the type of an object” … That can be changed easily info classes.
There are other places to give more extensive explanations if you prefer:
Finally, I recommend checking out this great site where refactoring conditional is explained in a way… let’s say different. 🙂