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?
- A. Single Responsibility; split RobotWorker into two classes
- B. Dependency Inversion; inject the worker
- C. Open/Closed; subclass RobotWorker
- 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.
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
- How many of these subclass changes violate the Liskov Substitution Principle? 1. The overriding method accepts a wider range of inputs…
- An area calculator contains if shape.type == "circle": … elif shape.type == "square": …, and every new shape requires editing this…
- How many of these statements are correct? 1. Dependency Inversion is a design principle: high- and low-level modules should both depend on…
- Code contains order.getCustomer().getAddress().getCity().toUpperCase(). Which principle does it most directly violate, and why does it…
- A module reads a raw record, cleans it, and passes the cleaned record to a parser whose output is passed to a validator - each step's…
- Match each scenario with its coupling type. P: a module passes a flag telling the callee which of several operations to perform. Q: a…