CS FundamentalsHardProduct-company design interview

A Worker interface declares work(), eat() and sleep(). RobotWorker implements it and leaves eat() and sleep() throwing 'not supported'. Which principle is violated, and what is the fix?

  1. A. Single Responsibility; split RobotWorker into two classes
  2. B. Dependency Inversion; inject the worker
  3. C. Open/Closed; subclass RobotWorker
  4. D. Interface Segregation; split it into smaller interfaces such as Workable and Feedable so robots implement only Workable

Correct answer: D. Interface Segregation; split it into smaller interfaces such as Workable and Feedable so robots implement only Workable

ISP says clients should not be forced to depend on methods they do not use. The dummy methods also hint at an LSP problem, but the root cause is the fat interface.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic