intermediateSOLID Principles

What is the Open-Closed Principle, and what does 'open for extension, closed for modification' actually mean in practice?

A class should be extendable to support new behavior without changing its existing, already-tested source code. In practice, this usually means depending on an abstraction (an interface) and adding new behavior by writing a NEW class that implements it, rather than adding another if/else branch to an existing class — e.g. adding a new PaymentMethod by creating a new class implementing a PaymentStrategy interface, instead of editing a giant switch statement inside PaymentProcessor.

This is a Pro question

Sign in, then upgrade to Pro or Power to unlock this question and the full Interview Prep bank.

What is the Open-Closed Principle, and what does 'open for extension, closed for modification' actually mean in practice?

Next Step

Continue to Proxy pattern vs Decorator pattern — both wrap an object, so what's the real difference in intent?← Back to all Design Patterns & LLD questions