Java Adapter and Facade Patterns: Integrate Incompatible Code Cleanly
Maya's bookstore now sells online, and the shop needs to take card payments. The shop already has a payment account with a legacy gateway, LegacyPay — a vendor library the shop cannot change. Its jar is signed, the vendor is long gone, and three other systems already depend on its exact behavior. It speaks a different language from the rest of the shop: amounts in cents as a plain long , and integer status codes instead of results. Meanwhile, checkout itself is scattered: the web handler reserves stock, calls the gateway, creates the shipment, and sends the confirmation — and the phone-order tool repeats the same four steps, with its own copy of the error handling. The question this post asks: how do you use code you cannot change, and how do you stop every caller from having to know how checkout works? Post 1 asked what varies? Post 2, Java Singleton Pattern: Enum, Lazy Holder & Double-Checked Locking Explained , asked how many? Post 3, Java Factory Pattern: Factory Method...