The open-closed principle is one of the SOLID principles for object-oriented programming, and it states that software components, like classes and methods, should be open for extension and closed for modification. In other words, it should be possible to extend the program’s functionality without modifying its existing parts.

When successfully employed, this principle significantly improves the modularity of the solution—replacing nasty conditionals spread everywhere with easy-to-understand replaceable plug-and-play components.

In the video below, I walk through a refactoring of a class to achieve a higher degree of modularity.