Author image

Adapter/Wrapper/Facade Design Pattern


Here we will disambiguate the Adapter Wrapper Facade Software Design patterns.

A confused pattern, yes.
It has many names.
Adapter, Facade, Wrapper.
But they're all pretty much the same..

The Adapter (aka Facade aka Wrapper class) wraps a legacy class with a new interface into an updated class that respects the new interface.

It is most often used to make existing classes work with others (perhaps new ones) without modifying their source code. Many Windows WinAPI functions are an example of this.

Design

  • an interface (perhaps legacy) is not compatible with the current system needs
  • an abstract base class is created that specifies the desired interface
  • an adapter class is defined that publicly inherits the interface of the abstract class, and privately inherits the implementation of the legacy class
  • this adapter class “(impedance) matches”...

Author image

Function Reference


My implementation of a functionRef/functionView variant. Why? I desperately wanted to know just how std::function<> works. So I scoured the tutorials, books what have you, in order to find more information and ended up creating a sort of lightweight variant of it.

The skills you need to have under your belt before attempting this tutorial are:

  1. Type erasure.
  2. callable objects
  3. std::invoke
  4. higher order functions
  5. lambda calculus - just a smattering knowledge

Based on std::function, functionRef is a non-owning wrapper for an arbitrary callable object.

Implementation notes:

  • A primary template is used to match the complete type of a callable, say void( int, int ) or int. The primary template remains an empty struct.
  • We want to differentiate the function type...

1