© Kelt Dockins 2017

Kelt Dockins, Design Patterns in PHP and Laravel, 10.1007/978-1-4842-2451-9_9

9. Adapter

Kelt Dockins

(1)Dolph, Arkansas, USA

$> git checkout adapter

Intent

Convert the interface of a class into another interface that the clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.1

Applications

Sometimes you want to use existing code but the interface does not match what you need. For example, you want to utilize vendor/outside code without rewriting all of your existing code. It is analogous to fitting a square peg in round hole. A square peg can fit inside any round hole, provided the peg is small enough. You should take care to adapt what is needed because the more methods ...

Get Design Patterns in PHP and Laravel now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.