Adapter Pattern


Adapter is a structural design pattern that works as a bridge between two incompatible interfaces, allowing them to collaborate. This pattern involves a single class which is responsible to join functionalities of independent or incompatible interfaces.


Design principles (link):

  • (OK) Single Responsibility Principle - You can separate the interface or data conversion code from the primary business logic of the program.
  • (OK) Open Closed Principle - You can introduce new types of adapters into the program without breaking the existing client code, as long as they work with the adapters through the client interface.
  • (OK) Dependency Inversion Principle - Client talks to abstraction (target interface) and adapter implements abstraction (target interface)


Relations with Other Patterns

  • Facade simplifies existing interface, normally wrapping a whole subsystem. Adapter adapts existing interface, wrapping only one class.
  • Decorator wraps a class to add functionality, Adapter wraps class to change its interface.
  • Strategy delegates work to the current subclass in the context, while Adapter always delegates work to the same class which it wraps.

Comments

Popular Posts