Design Patterns Explained
  • Getting Started
  • SOLID Principles
    • Single Responsibility Principle
    • Open / Closed Principle
    • Liskov Substitution Principle
    • Interface Segregation Principle
    • Dependency Inversion Principle
  • Design Patterns
    • Creational Patterns
      • Abstract Factory Pattern
      • Builder Pattern
      • Factory Pattern
      • Prototype Pattern
      • Singleton Pattern
    • Behavioral Patterns
      • Chain Of Responsibility Pattern
      • Command Pattern
      • Interpreter Pattern
      • Iterator Pattern
      • Mediator Pattern
        • Example 1
      • Memento Pattern
      • Observer Pattern
      • State Pattern
      • Strategy Pattern
        • Example 1
      • Template Method Pattern
      • Visitor Pattern
    • Structural Patterns
      • Adapter Pattern
      • Bridge Pattern
      • Composite Pattern
      • Decorator Pattern
      • Facade Pattern
      • Flyweight Pattern
      • Proxy Pattern
  • Roadmap
Powered by GitBook
On this page
  • Intent
  • Also known as
  • When to use
  • Structure
  • Examples

Was this helpful?

  1. Design Patterns
  2. Structural Patterns

Adapter Pattern

PreviousStructural PatternsNextBridge Pattern

Last updated 4 years ago

Was this helpful?

Intent

Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.

Also known as

Wrapper

When to use

  1. If we want to use an existing library that has an interface different than our code requires.

  2. If we want to easily change the existing libraries or have more than one used in the code, so we can define one Adapter interface, and adapt any number of different libraries in the different Adapter classes (Open / Closed Principle).

Structure

  • Target: defines the interface our code needs.

  • Adaptee: the existing library that needs to be adapted.

  • Adapter: adapts the adaptee to the required target interface.

Examples

Source Code

UML

// TODO

// TODO

You can find the tests .

here
Example 1
Example 2