← All Quizzes
What is the Open/Closed Principle (OCP)?
Explanation
The Open/Closed Principle (OCP), the O in SOLID, states that software entities (classes, modules, functions) should be open for extension but closed for modification. This means you should be able to add new functionality without changing existing code. OCP is achieved through abstraction (interfaces, abstract classes), polymorphism, and design patterns like Strategy and Decorator. OCP reduces the risk of introducing bugs when adding features and is fundamental to maintainable, extensible software design.