What is the best way to replace or substitute if..else if..else trees in programs?

These constructs can often be replaced by polymorphism. This will give you shorter and less brittle code.


In Object Oriented languages, it's common to use polymorphism to replace if's.

I liked this Google Clean Code Talk that covers the subject:

The Clean Code Talks -- Inheritance, Polymorphism, & Testing

ABSTRACT

Is your code full of if statements? Switch statements? Do you have the same switch statement in various places? When you make changes do you find yourself making the same change to the same if/switch in several places? Did you ever forget one?

This talk will discuss approaches to using Object Oriented techniques to remove many of those conditionals. The result is cleaner, tighter, better designed code that's easier to test, understand and maintain.