6 Adapter

1. Intro

  • similar to power adapter
  • different voltage requirements
  • Plug type (Europe, UK, USA)
  • we cannot modify our gadgets
  • Adapter is a contract which adopts existing interface X to conform to interface Y.
  • Create an API to adapt to other API

  • First of Structural Pattern

2. Adapter (no caching)

  • e.g. LineToPointAdapter - generate points from Line.
  • Square to Rectangle Adapter.

3. Adapter (Caching)

  • Cache to reduce generations.

Summary

  • How to implement
  • Determine API you have and API you need to Adapt
  • Create a component which aggregates the adapter