Skip to content

Interface Segregation

Medium — good to knowArchitecture

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."

Made with passive-aggressive love by manoga.digital. Powered by Claude.