Back

Interface Segregation

The I in SOLID: don't force code to depend on methods it doesn't use. Prefer several small, focused interfaces over one big one.

// Bad: a robot is forced to implement eat()
interface Worker {
  work(): void
  eat(): void
}

// Good: small interfaces, combine as needed
interface Workable { work(): void }
interface Eatable { eat(): void }

class Human implements Workable, Eatable {
  work() {}
  eat() {}
}
class Robot implements Workable {
  work() {}
}

Roadmap