The OCP states that software entities should be open for extension but closed for modification.
The ambiguity of this statement can be resolved through two variations of the principle:
- Existing classes should be modified only in order to correct bugs. This restriction delivers the closed aspect of the principle. The open aspect is delivered through implementation inheritance or, in other words, inheritance with the goal of reusing rather than subtyping.
- Openness through polymorphism by definition also provides for closure, as extensibility is supported through substitution rather than modification. Unfortunately, substitution often leads to accidental complexity, which must be addressed by yet another principle--the LSP.
The primary ...