intermediateAdapter Pattern

When should you actually reach for the Adapter pattern instead of just modifying one of the two mismatched classes directly?

Adapter earns its place specifically when you don't control one side of the mismatch -- most commonly a third-party library or a legacy system you're not allowed to change. In those cases there's no option to rename a method or reorder its parameters, so a small translating class in between is the only way to make the incompatible class usable through the interface your application already depends on. If you own both classes involved in the mismatch, reaching for an adapter usually just adds an unnecessary layer of indirection; it's simpler to fix the signature mismatch directly. Adapter is a workaround for something outside your control, not a general-purpose way to connect any two interfaces.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to In the Memento pattern, why shouldn't the Caretaker be able to read the contents of a Memento it's holding?← Back to all Low-Level Design & Design Patterns questions