Use the Adapter pattern when…


You have:

  • A domain-specific interface.
  • A class to connect to with a mismatching interface.

You want to:

  • Create a reusable class to cooperate with yet-to-be-built classes.
  • Change the names of methods as called and as implemented.
  • Support different sets of methods for different purposes.

Choose the Adapter you need…

  • Class adapter
    • Simple and versatile, invisible to the client.
  • Object adapter
    • Extensible to subclasses of the adapter.
  • Two-way adapter
    • Enables different clients to view an object differently.
  • Pluggable adapter
    • Presence of adapter is transparent; it can be put in and taken out
    • Several adapters can be active.