intermediate
Adapter
Wrap an incompatible dependency behind the interface the application expects while isolating translation and error semantics.
Adapter wraps a third-party or legacy dependency behind the interface your application already expects. Translation covers method names, error shapes, pagination models, and async semantics. Good adapters are thin: they map protocols without re-implementing business rules.
On interviews: give an example adapting a vendor SDK to your repository port. Explain where mapping belongs versus domain services.
Common pitfalls: adapters that grow into business logic dumps; leaking vendor types through the port; one adapter reused for unrelated contexts.
The trade-off is flexibility versus complexity—know when the simpler path is enough.
Checklist:
- Define the target port before writing adapter.
- Map errors to application-level result types.
- Keep adapter stateless when possible.
- Test adapter with recorded vendor fixtures.