Exercise 1: Adapting a Pence-Based Legacy Gateway — Possible Solution ==================================================================== THE NEW ADAPTER, FOLLOWING THIS CHAPTER'S OWN TEMPLATE ------------------------------ class LegacyGateway2: def process(self, total_pence): return f'Legacy2 processed {total_pence} pence' class PaymentGatewayAdapter2: def __init__(self, legacy_gateway): self._legacy_gateway = legacy_gateway def pay(self, amount_dollars): total_pence = round(amount_dollars * 100) return self._legacy_gateway.process(total_pence) This mirrors this chapter's own PaymentGatewayAdapter exactly - the same wrap-and-translate shape, with the target method name (process instead of make_payment) and parameter name (total_pence instead of amount_cents) changed to match this specific legacy gateway's own interface, and the same dollars-to-hundredths conversion reused, since both cents and pence are hundredths of their respective currency units. VERIFYING THE CONVERSION AND THE UNMODIFIED checkout() CALL ------------------------------ Calling checkout(PaymentGatewayAdapter2(LegacyGateway2()), 19.99) returns 'Legacy2 processed 1999 pence' - confirming 19.99 dollars correctly became 1999 pence (19.99 * 100 = 1999), and confirming the exact same checkout() function from this chapter, completely unmodified, works correctly with this second, differently-shaped legacy gateway. WHY THIS CONFIRMS ADAPTER'S OWN GENERAL-PURPOSE VALUE ------------------------------ This chapter's own client function, checkout(), never needed to change to support this second, differently-named, differently-shaped legacy interface - only a new, small, self-contained adapter class was needed, exactly mirroring the same zero-change-to-existing-code benefit this course established as far back as Chapter 1. WHY THIS WORKS AS AN ANSWER ------------------------------ The new adapter class is built by directly mirroring this chapter's own established template, adjusted only where the target interface's own method and parameter names genuinely differ, and the result is verified both for the specific numeric conversion and for successful, unmodified reuse of the existing checkout() function.