Interface Segregation
ELI5 — The Vibe Check
Interface Segregation means don't force classes to implement methods they don't need. A Printer shouldn't have to implement a 'fax()' method just because some all-in-one machine does. Keep interfaces small and focused so nobody gets stuck implementing useless stuff.
Real Talk
The Interface Segregation Principle states that clients should not be forced to depend on interfaces they do not use. Large 'fat' interfaces should be split into smaller, more specific ones. Classes then implement only the interfaces relevant to their behavior.
Show Me The Code
// Bad: fat interface
interface Machine {
print(): void;
scan(): void;
fax(): void;
}
// Good: segregated interfaces
interface Printer { print(): void; }
interface Scanner { scan(): void; }
interface FaxMachine { fax(): void; }
class SimplePrinter implements Printer { print() {} }
When You'll Hear This
"That interface is too fat — split it per Interface Segregation." / "ISP keeps your implementations clean and focused."
Related Terms
Abstraction
Abstraction is hiding the messy details and showing only what matters.
Cohesion
Cohesion is how well the things inside a module belong together. High cohesion means all the stuff in a class is related — like a toolbox full of tools.
Dependency Inversion
Dependency Inversion says high-level code shouldn't depend on low-level code — both should depend on abstractions.
SOLID (SOLID)
SOLID is five rules for writing code that doesn't turn into a nightmare over time. Each letter stands for a different rule.