Adapter
Description
When a client and a service want to talk but speak different interface dialects, an adapter sits between them and translates. The adapter’s surface on the client-facing side matches the client’s expectations; its consumption side matches the service’s native shape; and the body of the adapter is the translation logic that bridges the gap. The mismatch can be at any level — type signature, protocol, encoding, units, calling convention, identifier scheme. What unifies the cases is the structural three-role architecture (client / adapter / service) plus an explicit naming of the mismatch the adapter absorbs. Adapters are the standard move when you can’t change either side (the service is third-party; the client is legacy code). They’re the don’t break the seam; live on it solution.Triggers
User-initiated: User says “I want X to work with Y but they don’t match,” or proposes a wrapper / shim / translation layer. Vocabulary cues: “adapter,” “shim,” “wrapper,” “translates between,” “bridges,” “converter,” “I can’t change either side.” Agent-initiated: Agent notices two components with structurally-compatible but interface-incompatible shapes — same data, different schema; same operation, different signature. Candidate inference: “introduce an adapter at the seam; explicitly name the mismatch the adapter absorbs.” Situation-shape signals: Third-party API call that can’t quite hand its result to the local code. Two libraries that should compose but don’t. Legacy system + new system both speaking some flavor of the same data. Cross-language FFI boundaries.Exclusions
- Both sides are under your control — when you can change either side, refactoring to a shared interface is usually cleaner than introducing an adapter; the adapter pattern is mostly for the can’t-change-either-side constraint.
- The mismatch is semantic, not syntactic — if the two systems disagree about what the data means (not just how it’s shaped), an adapter that just translates shape will silently propagate the semantic mismatch; you need an explicit reconciliation policy, not just an adapter.
- The mismatch is structurally large — if the adapter has to reconstitute significant missing information, it’s no longer an adapter; it’s a translator with synthesis, and the structural primitive shifts.
Structure
Relationships
- seam — adapters live at seams; choosing where to put the adapter is choosing which seam to absorb the mismatch at.
- surface — the adapter has two surfaces — the client-facing one and the service-facing one — and the translation work is the body between them.
- multi-channel-ingest — multi-channel ingestion is typically N adapters (one per channel) feeding a unified internal representation.
- leaky-abstraction — adapters are abstractions and so leak; the leak is usually the seam’s residual shape that didn’t quite translate (e.g., ORM cache invalidation, dongle power-draw mismatches).
- proxy — proxy is the same-interface sibling; adapter is the different-interface case.
Examples
Adapter in OOP · computer-science
Adapter in OOP · computer-science
ListAdapter wrapping an array to make it implement a List interface; the most literal GoF instance.Power plug adapters · engineering-and-technology
Power plug adapters · engineering-and-technology
Anti-corruption layer (DDD) · computer-science
Anti-corruption layer (DDD) · computer-science
Domain-Driven Design (Evans 2003) — *anti-corruption layer* as a load-bearing adapter at architectural boundaries. · computer-science
Domain-Driven Design (Evans 2003) — *anti-corruption layer* as a load-bearing adapter at architectural boundaries. · computer-science
National electrical plug/socket standards (NEMA Type A/B in North America, CEE 7 "Schuko" in continental Europe, BS 1363 Type G in the UK) and the IEC's unadopted universal standard IEC 60906-1. · engineering-and-technology
National electrical plug/socket standards (NEMA Type A/B in North America, CEE 7 "Schuko" in continental Europe, BS 1363 Type G in the UK) and the IEC's unadopted universal standard IEC 60906-1. · engineering-and-technology
USB-C (USB Type-C) Cable and Connector Specification, USB Implementers Forum (USB-IF) — §2.2 "USB Type-C to Legacy Cable Assemblies and Adapters"; DisplayPort Alt Mode. · engineering-and-technology
USB-C (USB Type-C) Cable and Connector Specification, USB Implementers Forum (USB-IF) — §2.2 "USB Type-C to Legacy Cable Assemblies and Adapters"; DisplayPort Alt Mode. · engineering-and-technology
Gamma, Helm, Johnson, Vlissides (1994), Design Patterns: Elements of Reusable Object-Oriented Software (Gang of Four). Structural pattern, ch. 4. · computer-science
Gamma, Helm, Johnson, Vlissides (1994), Design Patterns: Elements of Reusable Object-Oriented Software (Gang of Four). Structural pattern, ch. 4. · computer-science
Gang of Four (1994), *Design Patterns* — the OOP coinage as a named pattern. · computer-science
Gang of Four (1994), *Design Patterns* — the OOP coinage as a named pattern. · computer-science
Target interface confronted with an existing Adaptee whose method names and parameters don’t match; the Adapter class implements Target and delegates to Adaptee, performing whatever name/argument translation is required.The book’s contribution wasn’t the move itself — wrapping mismatched interfaces is older than OOP — but the naming: pinning down a portable, transmissible label for a recurring three-role architecture. Once the name existed, engineers could point at an instance and say “that’s an Adapter,” and the conversation about whether to refactor vs. wrap could happen in shared vocabulary.Winters, T., Manshreck, T., & Wright, H. (Eds.) (2020). *Software Engineering at Google: Lessons Learned from Programming Over Time*. O'Reilly. Hyrum's Law — observation by Hyrum Wright, so named by Titus Winters; also hyrumslaw.com. · computer-science
Winters, T., Manshreck, T., & Wright, H. (Eds.) (2020). *Software Engineering at Google: Lessons Learned from Programming Over Time*. O'Reilly. Hyrum's Law — observation by Hyrum Wright, so named by Titus Winters; also hyrumslaw.com. · computer-science
Language translation / interpreter · linguistics
Language translation / interpreter · linguistics
ORM · computer-science
ORM · computer-science
Protocol bridges · computer-science
Protocol bridges · computer-science
USB-C dongles · engineering-and-technology
USB-C dongles · engineering-and-technology