SOLID: I — Interface Segregation Principle

Clients shouldn't be forced to depend on methods they don't use. Prefer several small, focused interfaces over one big one.

Why it matters

Big 'do-everything' interfaces force classes to implement methods that make no sense for them, and every change to the big interface touches classes that don't care.

The idea

A giant interface forces every class that implements it to write methods it doesn't need (often empty, or throwing errors), and changes ripple into classes that don't care. Split interfaces by what their users actually need.

A TV remote with 80 buttons when you only need power, volume and channel. Give most people a simple remote, and an advanced one to those who need it.

A remote is one physical object. In code, too many tiny interfaces can be confusing too, so group methods that are always used together.

How it works

  1. Look for implementations full of empty methods or 'not supported' errors.
  2. Group the interface's methods by which clients actually call them.
  3. Make one small interface per group: Printer, Scanner, Fax.
  4. Classes implement only what they really do, and each client depends only on the small interface it uses.

Example

A Machine interface with print(), scan() and fax() forces a basic printer to implement fax(). Split it into Printer, Scanner and Fax; an office machine implements all three.

Key points

Common mistakes

Not true: Interface segregation means one method per interface.
In fact: It means no client should depend on methods it doesn't use. Group methods by what each client needs: one role may well need several.

In the interview

Interface segregation means small, client-specific interfaces, so classes don't implement methods they don't need — for example separate Printer and Scanner interfaces instead of one big Machine interface.

Part of Unit 5: Low-level design: OOP and SOLID in the free System Design course.