πŸ₯ΈAdapter

Adapter is a structural design pattern that allows objects with incompatible interfaces to collaborate.

circle-info

Warning: poi vi dico

Usage examples

The Adapter pattern is pretty common in C++ code. It’s very often used in systems based on some legacy code. In such cases, Adapters make legacy code work with modern classes.

Identification

Adapter is recognizable by a constructor which takes an instance of a different abstract/interface type. When the adapter receives a call to any of its methods, it translates parameters to the appropriate format and then directs the call to one or several methods of the wrapped object.

Pros & Cons

circle-check
circle-check
triangle-exclamation

Graphic Visual

Adapter design pattern
Ez++

Example

This example illustrates the structure of the Adapter design pattern. It focuses on answering these questions:

  • What classes does it consist of?

  • What roles do these classes play?

  • In what way the elements of the pattern are related?

Conceptual Example

main.cpp

output.txt

Last updated