Which statement best describes the Interface Segregation Principle?
Think about how interfaces affect client dependencies and code flexibility.
The Interface Segregation Principle states that clients should not be forced to depend on interfaces they do not use. This promotes smaller, more specific interfaces rather than large, general ones.
You are designing a payment system with multiple payment methods: CreditCard, PayPal, and Bitcoin. Which design best follows the Interface Segregation Principle?
Consider how to avoid forcing classes to implement methods they don't need.
ISP encourages creating smaller, specific interfaces so classes implement only what they need. Separate interfaces for each payment method avoid unnecessary dependencies.
A notification system supports Email, SMS, and Push notifications. As the system grows, which approach best supports scalability and follows ISP?
Think about how adding new notification types affects existing classes.
Separate interfaces allow adding new notification types without changing existing classes, supporting scalability and adhering to ISP.
What is a common tradeoff when applying the Interface Segregation Principle in system design?
Consider the balance between interface size and system complexity.
While ISP improves modularity, it can lead to many small interfaces, which may increase management overhead.
Given a system with a Printer interface having methods print(), scan(), fax(), and a class BasicPrinter implementing all methods but only supporting print(), what problem does this design illustrate?
Think about whether classes should implement methods they don't support.
BasicPrinter implementing unused methods violates ISP because it depends on methods it does not need, leading to unnecessary complexity.