What is the Interface Segregation Principle?
Why Interviewers Ask This
This is a differentiating question used for senior and lead roles. Interviewers want to see if you can explain not just what happens, but why — and what the trade-offs are in different approaches.
Answer
The Interface Segregation Principle (ISP) states: Clients should not be forced to depend on methods they do not use. Prefer many small, specific interfaces over one large, general interface ("fat interface"). ISP violation (fat interface): interface Worker { void work(); void eat(); void sleep(); void attendMeeting(); void writeReport(); } class HumanWorker implements Worker { public void work() { /* ... */ } public void eat() { /* ... */ } public void sleep() { /* ... */ } public void attendMeeting() { /* ... */ } public void writeReport() { /* ... */ } } // Problem -- Robot worker must implement methods that don't make sense: class RobotWorker implements Worker { public void work() { /* ... */ } public void eat() { throw new UnsupportedOperationException("Robots don't eat!"); } public void sleep() { throw new UnsupportedOperationException("Robots don't sleep!"); } public void attendMeeting() { /* maybe */ } public void writeReport() { /* maybe */ } }. ISP applied — segregated interfaces: interface Workable { void work(); } interface Eatable { void eat(); } interface Sleepable { void sleep(); } interface Reportable { void writeReport(); } interface Meetable { void attendMeeting(); } class HumanWorker implements Workable, Eatable, Sleepable, Reportable, Meetable { /* Implements all, makes sense */ } class RobotWorker implements Workable, Reportable, Meetable { /* Only relevant interfaces */ }. ISP in practice: // Bad: interface UserRepository with 15 methods // Good: interface UserReader { User findById(int id); List<User> findAll(); } interface UserWriter { void save(User user); void delete(int id); } interface UserSearcher { List<User> search(String criteria); }. Design cohesive interfaces. Clients get only what they need. Changes to one interface don't affect unrelated clients. ISP prevents "implementing interface = implementing everything even unneeded methods."
Common Mistake
Rushing to answer is a common mistake. Take two seconds to structure your response: definition → example → trade-off. This structure makes complex OOP Concepts answers easy to follow.