Skip to main content

Interface Bridging Workshop

Retrieval Prompts

  1. Describe Adapter in one sentence. What concrete thing is it trying to prevent from leaking?
  2. Describe Facade in one sentence. What distinguishes it from Adapter?
  3. Describe Bridge in one sentence. Why is it usually premature in small code?
  4. Name the single question that separates Adapter from Facade.
  5. 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:

  1. "We wrapped the Stripe SDK in an Adapter that also handles the business rule for failed charges."
  2. "Our Facade hides the subsystem so no one can use it directly."
  3. "We added a Bridge because we expect a second renderer someday."
  4. "Since the Adapter wraps the adaptee, it's the same as a Decorator."
  5. "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

  1. Draw the resulting layers on paper: domain, target interface, adapter, adaptee.
  2. Identify any type from the adaptee that leaked into the domain (this is a bug in the adapter).
  3. 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