Interface Segregation Principle: No Client Should Depend on Unused Methods
What you'll learn: How to avoid forcing clients to depend on interface methods they never use.
The Core Problem: Fat Interfaces
The Interface Segregation Principle (ISP) states that no client should be forced to depend on methods it doesn't use. When an interface contains too many methods—becoming a "fat interface"—clients that implement or depend on it are burdened with functionality they don't need.
Think of it like a Swiss Army knife. If you only need scissors, you don't want to carry around the knife, corkscrew, saw, and ten other tools. ISP says: give clients exactly the tools they need, nothing more.
Why This Matters
When clients depend on unused methods, several problems arise:
- Unnecessary coupling: Changes to methods you don't use can still break your code
- Confusing contracts: Implementing empty or exception-throwing methods just to satisfy an interface
- Difficult testing: You must accommodate methods you never call
- Reduced flexibility: Every client must handle the entire interface burden
The ISP Solution
Instead of one large interface, create smaller, more focused interfaces. Clients depend only on the interfaces they actually use. This is similar to separation of concerns and the Single Responsibility Principle you've already learned—but applied specifically to interfaces.
If different clients need different subsets of functionality, split the interface. Each client gets a lean, targeted contract containing only relevant methods.
Key Takeaway: The Interface Segregation Principle prevents fat interfaces by ensuring clients only depend on methods they actually need, reducing coupling and increasing flexibility.