What is "interface pollution" and which principle prevents it?
Answer
Interface pollution occurs when a single interface accumulates too many methods, forcing implementors to provide methods that are irrelevant to their actual role. This happens when interfaces grow over time without discipline, often because developers keep adding methods to a convenient existing interface. For example, an Animal interface that starts with eat() and breathe() and gradually gains fly(), swim(), and burrow() becomes polluted — most animals implement only a subset of these behaviors but are forced to provide empty or exception-throwing implementations for the rest. ISP directly prevents interface pollution by mandating that interfaces be client-specific. The solution is to split the fat interface into Flyable, Swimmable, and Burrowable interfaces that animals selectively implement.
Previous
How does the Decorator pattern support OCP?
Next
How do SOLID principles relate to YAGNI and DRY?
More SOLID Principles Questions
View all →- Intermediate How would you refactor a class that violates SRP?
- Intermediate How does the Strategy pattern support OCP?
- Intermediate What are the conditions for LSP compliance?
- Intermediate How does ISP prevent "fat interfaces"?
- Intermediate What is the difference between DIP and dependency injection containers?