CS FundamentalsHardGATE CS · TCS NQT Prime · Product Company SDE

A single 'Worker' interface forces every implementing class to provide both work() and eat() methods, even though a RobotWorker class has no meaningful concept of eating. Which principle addresses this problem, and what is the usual fix?

  1. A. Single Responsibility Principle; the fix is to merge Worker with every other interface in the system
  2. B. Interface Segregation Principle; split the fat interface into smaller, role-specific interfaces (e.g. Workable and Eatable) so clients only depend on what they actually need
  3. C. Open/Closed Principle; the fix is to never create new interfaces again
  4. D. Liskov Substitution Principle; the fix is to throw an exception from eat()

Correct answer: B. Interface Segregation Principle; split the fat interface into smaller, role-specific interfaces (e.g. Workable and Eatable) so clients only depend on what they actually need

ISP says clients should not be forced to depend on methods they do not use; splitting a bloated interface into smaller, more focused ones lets RobotWorker implement only Workable, avoiding a meaningless eat() method.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic