Last updated: Apr 29, 2026

Interface Segregation

Prefer small, focused interfaces over large general-purpose ones. Don’t force a class to implement methods it doesn’t need.

When an interface is too big, classes end up with empty method bodies or methods that just throw exceptions. That is a sign the interface is doing too much. Split it into smaller ones — a class can implement multiple small interfaces if it needs to.

Example

A Robot is forced to implement eat and sleep even though it does neither:

interface Worker {
  work(): void;
  eat(): void;
  sleep(): void;
}

class Robot implements Worker {
  work(): void {}
  eat(): void {} // robots don't eat
  sleep(): void {} // robots don't sleep
}

Split into focused interfaces so each class only implements what it actually does:

interface Workable {
  work(): void;
}

interface Feedable {
  eat(): void;
}

interface Restable {
  sleep(): void;
}

class Human implements Workable, Feedable, Restable {
  work(): void {}
  eat(): void {}
  sleep(): void {}
}

class Robot implements Workable {
  work(): void {}
}