Applying the Open-Closed Principle: Never Write an IF Statement Again

Violations of the open-closed principle (the O in SOLID) are the plague of OO programming. Unlike the Andromeda Strain before it, the symptoms of this disease, innocuous IFs and CASEs, are quietly waiting for just the right moment to render your software unmaintainable. The agents work slowly and quietly, in the shadows, like digging a hole with a soup spoon. One day you wake only to realize you’ve sunk into a pit of technical debt. OK, it’s probably not that bad, but violating the Open-Closed principle does have the potential to shorten the life of any OO code. The key is to identify violations as they are occurring so that we keep the power to extend the software without also needing to change it. This session demonstrates refactoring techniques to eliminate violations of the principle and some tips for identifying the early. Examples are provided mainly in Groovy, but analogous code will be provided in a variety of other languages.