60% of the time, I replace conditionals with polymorphism every time:
Maintainability: we now had two ways of looking for error messages: from the errors collection, and from an exception raised during validation. This commit makes it clear that at least six places need to change if we add any more. Maintainability: this commit revealed that AllowValueMatcher had too many concerns: it both finds error messages to check, and parses the options and errors to determine whether or not the errors were expected. Readability: AllowValueMatcher is now too large to understand at a glance, weighing in at 26 methods. Readability: having two logical paths for every method resulted in a lot of long method names. In addition, having so many methods makes it more difficult to reduce the vertical distance between a method and the methods that reference it. Testability: making sure that the various forks work as expected requires testing everything in AllowV...
Full article:
http://robots.thoughtbot.com/post/31728620503/refactoring...