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?
- A. Single Responsibility Principle; the fix is to merge Worker with every other interface in the system
- 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
- C. Open/Closed Principle; the fix is to never create new interfaces again
- 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.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- A team wants to run two full versions of a service simultaneously in production, routing a fixed percentage of traffic to each to directly…
- A subsystem has many complex interacting classes (video codecs, audio mixers, subtitle renderers). Client code just wants a single, simple…
- Using Basic COCOMO for a embedded mode project (Effort = 3.6 × (KLOC)^1.2 person-months), what is the estimated effort for a 50 KLOC…
- A tester designs test cases specifically to exercise every branch of an if-else statement in the source code. This is an example of:
- A class diagram marks an attribute's visibility with a '#' symbol before its name. What does this denote?
- Which of these is a defining feature of the V-model, distinguishing it from plain waterfall?