LLD Hub
Learn

Interface SegregationClients shouldn't depend on unused methods

Split fat interfaces so clients only depend on what they use. · No dummy / throw implementations for unused methods.

Watch

Watch, then scroll down for code and practice.

In code

Segregated rolesTypeScript
interface Workable {
  work(): void;
}
interface Feedable {
  eat(): void;
}

class Human implements Workable, Feedable {
  work() {}
  eat() {}
}

class Robot implements Workable {
  work() {}
}

📘 Key ideas

The principle

No client should be forced to implement methods it doesn't use. Fat interfaces force implementors to stub out irrelevant methods.

The smell

RobotWorker throws UnsupportedOperationException for eat() and sleep(). That's a sign the Worker interface is too fat.

The fix

Split into Workable, Eatable, Restable. HumanWorker implements all three. RobotWorker implements only Workable.

Benefit

Supervisor only depends on Workable — it can manage both humans and robots without knowing about eating or sleeping.

🧠 Practice — Apply What You Learned

🚀 Now apply what you learned

Pick a problem above, write your solution, and get AI feedback on your design.

Start Practice →