Which statement best describes the Open/Closed Principle in software design?
Think about how to add new features without changing existing code.
The Open/Closed Principle means you can add new behavior by extending code, not by changing existing code, which helps avoid bugs.
You have a payment processing system that currently supports credit cards. You want to add support for new payment methods without changing existing payment code. Which design approach follows the Open/Closed Principle?
Think about how to add new payment types without changing existing code.
Using interfaces and polymorphism allows adding new payment types by creating new classes, keeping existing code unchanged.
You have a notification system that sends alerts via email. You want to add SMS and push notifications without modifying existing email notification code. What is the best scalable design following the Open/Closed Principle?
Consider how to add new notification types without changing existing classes.
Using an interface and separate classes for each notification type allows adding new types by extension, not modification, supporting scalability.
What is a common tradeoff when strictly applying the Open/Closed Principle in system design?
Think about how adding extensions affects code structure.
Following Open/Closed Principle often leads to more classes and interfaces, increasing complexity but improving extensibility and safety.
Given a logging component that writes logs to a file, which change violates the Open/Closed Principle?
Options describe changes to add new logging outputs.
Look for changes that modify existing code instead of extending it.
Modifying existing classes to add new behavior breaks the Open/Closed Principle; new functionality should be added by extension.