LLDHub
Problems·ISP: Break the Fat Worker Interface
SOLIDL2 · Easy

ISP: Break the Fat Worker Interface

Problem

A Worker interface has four methods: work(), eat(), sleep(), requestLeave(). HumanWorker implements all. RobotWorker also implements Worker, but has to throw UnsupportedOperationException for eat(), sleep(), and requestLeave(). This forces clients to depend on methods they don't use. Apply Interface Segregation.

Requirements

  • Break Worker into: Workable (work()), Eatable (eat()), Restable (sleep()), LeaveTakeable (requestLeave())
  • HumanWorker implements all four
  • RobotWorker implements only Workable
  • Supervisor depends only on Workable — can manage both humans and robots
  • HRSystem depends on Eatable + Restable + LeaveTakeable — only works with humans

Constraints

  • No class should implement methods that throw UnsupportedOperationException
  • Supervisor must NOT need to change when RobotWorker is added
✓ Saved