by shigemk2


97 Things Every Programmer Should Know 59 Missing Opportunities for Polymorphism

polymorphism isn't simply about alternate implementations. Used carefully, polymorphism creates tiny localized execution contexts that let us work without the need for verbose if-then-else blocks.

While there are cases where it's much more practical to use if-then-else instead of polymorphism, it is more often the case that a more polymorphic coding style will yield a smaller, more readable and less fragile codebase. The number of missed opportunities is a simple count of the if-then-else statements in our code.