Adapter Pattern


As the name suggests, the Adapter pattern allows us to adapt the available interface to what we need. A voltage adapter helps us obtain 110V out of a 230V socket. Similarly, the Adapter pattern provides for an adapter class that can map the available interface to the required interface.

This pattern has three main roles - client, adapter and the adaptee.

The thin Adapter is one that just maps the method names. For example, if we have an adaptee that provides a method trigger(), and the client needs the same functionality in a method name start(), the adapter provides a method named start() that simply invokes the method trigger(). This is a thin adapter. A thick adapter could do a lot more than that.

Here, we must be careful to make sure that the adapter is only adapting the interface - and not adding a functionality of its own. This separation of concern is very important to ensure maintainability.