2. Open-Closed Principle

Created Thursday 14 August 2014



Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification

Open to Extension

New behavior can be added in the future

Closed to Modification

Changes to source or binary code are not required

Change behavior without changing code

3 Approaches to Achieve OCP

When to apply

Conformance to OCP yields flexibility, reusability, and maintainability

Know which changes to guard against, and resist premature abstraction

Related Fundamentals

Recommended Reading