REVISION AND PRACTICE

Section-based revision questions and reasoning

2 min read
On this page 10 headings

Question 1

A class manages seller details, inventory and sales reports. Which principle is at risk?

Answer and reasoning: SRP: the class has multiple reasons to change. Split seller, inventory and reporting responsibilities.

Question 2

A new payment provider requires editing Seller.processPayment(). Which principle suggests a redesign?

Answer and reasoning: DIP: Seller should depend on a payment abstraction. OCP also explains why extensibility is desirable.

Question 3

An e-book processor must provide an empty deliver() method. Why is that a problem?

Answer and reasoning: ISP: its interface includes a method irrelevant to the digital-order client.

Question 4

A subclass has the same method signature but throws an error for inputs accepted by its base class. Is LSP satisfied?

Answer and reasoning: No. Substitutability requires honoring the behavioral expectations of the base type.

Question 5

A client needs one operation to create an order, notify the seller and dispatch a parcel. Which pattern?

Answer and reasoning: Facade: it provides one simplified entry point to multiple subsystem steps.

Question 6

A product priced in dollars must get its cost in rupees from an existing ConversionCalculator it cannot call directly. Which pattern?

Answer and reasoning: Adapter (CostCalculatorAdapter): wraps the existing conversion library’s incompatible interface.

Question 7

A Book has mandatory ISBN, title and cost and optional author, published year and description. Which creational pattern?

Answer and reasoning: Builder: construct it step by step instead of using many telescoping constructors.

Question 8

Buyers should automatically learn about newly launched products. Which pattern?

Answer and reasoning: Observer: register buyers and notify them on a launch event.

Question 9

An order queue can be processed FIFO or by customer priority. Which pattern?

Answer and reasoning: Strategy: encapsulate the alternative algorithms behind a shared interface.

Question 10

You need to iterate over a tree without revealing its internal node representation. Which pattern?

Answer and reasoning: Iterator: separate traversal from collection representation.

YOUR STUDY PROGRESS

Finished this section? Save your progress.

Back to top ↑