TDD and the SOLID principles (Part 3 – OCP)

Wednesday, September 7, 2011

Table of contents: Part1 – Indrocution Part 2 – SRP Part 3 – OCP (this post) Part 4 – LSP Part 5 – ISP Part 6 – DIP Part 7 – Conclusion The Open/Close Principle The Open/Close Principle states that: SOFTWARE ENTITIES (CLASSES, MODULES, FUNCTIONS, ETC.) SHOULD BE OPEN FOR EXTENSION, BUT CLOSED FOR MODIFICTION. This statement pretty much says it all, and naturally extends the Single-Responsibility principle: Classes (and functions, etc.) should be kept as simple as possible (having a single responsibility) and therefore should never have to change. Therefore, if you want to add functionality to your system you should add new code instead of changing existing one....