-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Node.js Design Patterns - Second Edition
By :
The Adapter pattern allows us to access the functionality of an object using a different interface. As the name suggests, it adapts an object so that it can be used by components expecting a different interface. The following diagram clarifies the situation:

The preceding diagram shows how the Adapter is essentially a wrapper for the Adaptee, exposing a different interface. The diagram also highlights the fact that the operations of the Adapter can also be a composition of one or more method invocations on the Adaptee. From an implementation perspective, the most common technique is composition, where the methods of the Adapter provide a bridge to the methods of the Adaptee. This pattern is pretty straightforward, so let's immediately work on an example.
We are now going to build an Adapter around the LevelUP API, transforming it into an interface that is compatible with the core fs module. In particular, we will make sure that every call to...
Change the font size
Change margin width
Change background colour