What is the Interface Segregation Principle (ISP)?
ISP is the fourth principle in SOLID. It addresses the problem of bloated interfaces that force implementing classes to provide empty or meaningless implementations for methods they do not need.
Core Problem It Solves
When an interface grows too large with many methods, classes that implement it must provide all methods even if they only need a subset. This creates several issues:
First, implementing classes carry unnecessary baggage with stub methods that throw exceptions or do nothing.
Second, changes to unused methods still require recompilation of all implementing classes.
Third, clients that depend on the interface see methods they cannot or should not call, violating the Principle of Least Surprise.
The Solution
Split large interfaces into smaller, role-specific interfaces. Each interface represents a cohesive set of behaviors. Implementing classes choose only the interfaces relevant to their responsibilities.