Skip to main content

πŸ” Adapter vs Bridge

βœ… Purpose of Comparison​

Both Adapter and Bridge are classified as structural patterns, but they serve different purposes. While their diagrams may appear similar at first glance, their design intent and usage scenarios diverge significantly. Understanding these distinctions helps engineers choose the most appropriate abstraction technique depending on the contextβ€”whether for retrofitting compatibility or promoting future extensibility.

βœ… Comparison Overview​

AspectAdapterBridge
Primary PurposeEnsure compatibility with an existing interfaceSeparate abstraction and implementation
Change DirectionApplied to existing classes (bottom-up)Designed from the start (top-down)
FlexibilityLow (wraps fixed interface)High (independent extension of both sides)
Use Case TimingWhen integrating external or legacy componentsWhen designing extensible frameworks
ReusabilityLimited to specific contextBroad across various implementations

βœ… Similarities​

  • Both decouple classes to promote modularity and reduce tight coupling.
  • Both introduce an intermediary layer between interface and implementation.
  • Both are effective in managing changing requirements without modifying core logic.

βœ… Key Differences​

ViewpointAdapterBridge
Direction of UseWraps existing codeDesigned proactively for extension
Client AwarenessClient uses Target interfaceClient uses Abstraction
FlexibilityAdapts one class at a timeEnables NΓ—M abstraction-implementation
Change FrequencyUsed when target can't be changedUsed when both sides evolve independently
Design StrategyCompatibility wrapperLayered extension architecture

βœ… When to Use Which?​

  • βœ… Need to connect to an existing, incompatible API β†’ Use Adapter
  • βœ… Want to separate concerns cleanly for future growth β†’ Use Bridge
  • βœ… Working with legacy systems or third-party code β†’ Adapter
  • βœ… Building a scalable, pluggable architecture β†’ Bridge

βœ… UML Class Diagrams​

Adapter Pattern​

Bridge Pattern​

βœ… Practical Design Notes​

  • βœ… Adapter is useful for ad-hoc integration, but overuse can lead to structural complexity.
  • βœ… Bridge offers high extensibility, but may require more upfront design effort.
  • ▢️ Example:
    Use Adapter when integrating with a legacy notification API.
    Use Bridge when you want to separate notification types (e.g., error/warning) from delivery methods (e.g., email/Slack).

βœ… Summary​

  • Adapter acts as a retrofitted wrapper to provide compatibility.
  • Bridge is a structural separation of abstraction and implementation for extensibility.
  • While the structures may look similar, they differ significantly in intended usage and expansion direction.
  • Choosing the right pattern depends on the architectural goals at the time of design.