How is the Interface Segregation Principle different from the Single Responsibility Principle?
SRP is about a class having one reason to change. ISP is about the interface a client sees: it should be small and fit that client's needs. One is about implementation, the other about the contract.
Explain it simply
A multi-function printer can be one well-built machine (it has a single job: producing paper output from your files). But a student who only wants to print should see a "Print" button, not scan, fax and staple. The machine's internal organisation is the SRP question; what each person sees on screen is the ISP question.
A class may well implement several small interfaces, each used by a different client.
Example
interface Printer { void print(Doc d); }
interface Scanner { Doc scan(); }
class AllInOne implements Printer, Scanner { // one class, two narrow contracts
public void print(Doc d) { ... }
public Doc scan() { ... }
}
void submitAssignment(Printer p, Doc d) { // sees only print()
p.print(d);
}submitAssignment can be tested with a trivial fake Printer and does not break if Scanner changes.
What to say in the interview
"SRP limits why a class changes; ISP limits what a client has to know about it. A class can implement several narrow interfaces, and each client depends only on the one it needs. They work together but are not the same."
Common mistakes
- Treating ISP as a rule about class size.