How can you design classes that are open for extension but closed for modification?
To design classes that follow OCP:
- Use abstraction (interfaces or abstract classes).
- Rely on polymorphism and inheritance.
- Apply composition over inheritance when suitable.
- Follow design principles like Strategy, Decorator, or Template Method patterns.
✅ Extend behavior through new classes rather than modifying existing code.