Module 02 · SOLID and friends · Drill
SOLID drill
Scenario prompts that check whether solid and friends is usable under pressure. Answer out loud, then compare.
0 of 4 graded
Prompt 1
A ReportService class loads sales data with raw SQL, computes totals and tax, formats PDF and Excel output with a switch on format, emails the result and logs to a file. Walk through which SOLID principles it violates and refactor it, naming the classes and interfaces you would end up with.
Prompt 2
A Storage interface has read, write, delete and listVersions. The team adds a ReadOnlyArchiveStorage that throws UnsupportedOperationException on write and delete, and a CdnStorage that does not support listVersions. Callers now wrap calls in try/catch and instanceof checks. Diagnose and fix the design.
Prompt 3
A shipping-cost calculator has an if-else chain over carriers (UPS, FedEx, DHL, local courier), each branch calling a vendor SDK directly, and the chain is copied into checkout and returns. Product will add two carriers next quarter. Refactor it with open-closed and dependency inversion, and say what you would deliberately not abstract.
Prompt 4
In code review you see: invoice.getCustomer().getAccount().getBillingAddress().getCountry().getVatRate() used in six places, a shared formatName(user, isAdmin, isShort, isLegal, locale) helper with growing flags, and an abstract BaseEntityManager with 40 methods 'for future needs'. Name the principle each one breaks and the fix.