Module 20 · OOP fundamentals · Drill
OOP fundamentals drill
Scenario prompts that check whether oop fundamentals is usable under pressure. Answer out loud, then compare.
0 of 4 graded
Prompt 1
Design the core classes for a library's book loans: members borrow copies of books, a member may hold at most 5 loans, a copy cannot be lent twice, and overdue loans block new borrowing. Show where each rule lives and how encapsulation protects it.
Prompt 2
A notification system has a send(user, message, channel) method with a switch over EMAIL, SMS and PUSH. Product wants WhatsApp next quarter and Slack after that. Refactor the design using inheritance, polymorphism and interfaces, and say what you would not use inheritance for.
Prompt 3
Explain to a junior engineer why this prints 'object' and not 'string': void show(Object o) and void show(String s) are both defined, Object x = "hi"; show(x);. Then explain how a.speak() picks Dog's method when a is declared Animal, and when you would need double dispatch.
Prompt 4
A team's OrderService constructs a MySqlOrderRepository, a StripeClient and calls Instant.now() directly. Tests need a database, a Stripe sandbox and cannot test expiry logic. Redesign it with abstraction and interfaces, and say which dependencies deserve an interface and which do not.