Sitemap
Youssef

Youssef

Software Engineer

Member-only story

The Adapter Design Pattern: Making Incompatible Interfaces Work Together

How to bridge incompatible APIs without changing the code that already depends on them.

8 min read4 days ago

--

👋 Hi, I’m Youssef | 💼 LinkedIn · ✍️ Medium

🔓 Not a Medium member? No worries! Read the full story for free here

The Adapter pattern lets two pieces of code work together even when their interfaces don’t match. Instead of changing either side, you place a small adapter between them that translates one interface into the other.

Think of a travel plug adapter. Your laptop charger has a US plug, while the hotel wall has a European socket. You don’t rewire the hotel or modify the charger. The adapter bridges the difference so both can work as designed.

Press enter or click to view image in full size
Before: incompatible. After: an adapter in between, nothing rewired.

This article explains the problem the Adapter pattern solves, how it is structured, a practical PHP example, where you’ll encounter it in the PHP ecosystem, and when to use it — and when not to.

The Problem: Interfaces That Don’t Fit

The problem occurs when a service exposes a different interface from the one your application expects, and changing either side isn’t practical. This commonly happens in cases like these:

--

--