Interface Bridging Workshop
Retrieval Prompts
- Describe Adapter in one sentence. What concrete thing is it trying to prevent from leaking?
- Describe Facade in one sentence. What distinguishes it from Adapter?
- Describe Bridge in one sentence. Why is it usually premature in small code?
- Name the single question that separates Adapter from Facade.
- Name the single question that separates Bridge from Strategy.
Compare and Distinguish
Separate these pairs clearly:
- Adapter vs Facade
- Adapter vs Proxy
- Adapter vs Decorator
- Facade vs "service class"
- Bridge vs Strategy
- Bridge vs plain composition
Common Mistake Check
For each statement, identify the error:
- "We wrapped the Stripe SDK in an Adapter that also handles the business rule for failed charges."
- "Our Facade hides the subsystem so no one can use it directly."
- "We added a Bridge because we expect a second renderer someday."
- "Since the Adapter wraps the adaptee, it's the same as a Decorator."
- "This class implements both the target and the adaptee interface, so it's a clean object adapter."
Mini Application
Pick one third-party shape you actually use (HTTP client, logger, queue client, payment SDK, filesystem API). Do all three:
Step 1 -- Target Interface
Write the interface your domain wishes existed. Use your domain's vocabulary, not the SDK's. Keep it small: two to four methods.
Step 2 -- Adapter Implementation
Implement an Adapter:
- accepts the adaptee through its constructor (DI)
- translates arguments to the adaptee's types
- translates results back into domain types
- maps at least one adaptee exception to a domain exception
Step 3 -- Facade (if applicable)
If the third-party has many classes, add a small Facade on top of the Adapter that covers the 80% case in one method. Leave at least one method unimplemented on purpose.
Step 4 -- Swap Test
Implement a fake version of the target interface and swap it in at the composition root. Prove your domain code did not change.
Reflection
- Draw the resulting layers on paper: domain, target interface, adapter, adaptee.
- Identify any type from the adaptee that leaked into the domain (this is a bug in the adapter).
- Consider a Bridge: do you have two axes of variation? If yes, sketch it. If no, say so out loud and move on.
Evidence Check
This page is complete only if you have:
- a working adapter against real third-party code
- at least one exception mapping
- a fake implementation of the target interface
- a written paragraph distinguishing Adapter from Facade using this exercise as the example