How does OCP relate to interfaces and abstract classes?
- Interfaces and abstract classes provide a contract that other classes can
implement or inherit.
- They enable polymorphism, which allows behavior to be extended without altering
existing code.
- By programming to abstractions (not concrete implementations), you can easily
introduce new behavior (via new implementations) while keeping the core logic
unchanged.
✅ OCP encourages extending via new subclasses or interface implementations, not
modifying existing ones.
Liskov Substitution Principle (LSP)