# Design patterns: Adapter

> The Adapter design pattern with examples in PHP

- URL: https://mautoblog.com/en/posts/design-patterns/adapter/
- Language: en
- Published: 2024-09-27
- Updated: 2026-10-14
- Author: Mauto
- Categories: Software Development, Technology
- Tags: Software Architecture, Best Practices, PHP
- Guide: Design Patterns (part 7)
- Translation (it): https://mautoblog.com/posts/design-patterns/adapter/

---
The Adapter pattern is a structural design pattern that allows incompatible interfaces to work together.

## Characteristics of the Adapter pattern
1. **Compatibility between interfaces:** The Adapter Pattern lets you adapt an existing interface to another interface the client expects, enabling incompatible classes to work together.
2. **Separation of responsibilities:** It promotes separation between the client code and the classes that need to be adapted. The client doesn't have to change its own code to use the adapted classes.
3. **Reuse of existing code:** It lets you reuse existing classes without modifying them, making it easier to integrate new functionality into an application.
4. **Flexibility:** Adapters can easily be created to adapt new classes, keeping the application flexible and making it easier to integrate different components.
5. **Translating calls:** It translates the client's calls into the format expected by the adapted class.
6. **Ability to adapt different kinds of classes:** It can adapt both classes and interfaces, letting you work with various kinds of components, including external objects or third-party libraries.
7. **Incremental development:** It supports an incremental development approach, letting you add new features or components without having to restructure the entire system.

### Example in PHP:
```php
class OldPaymentSystem {
    public function pay() {
        return "Payment with the old system.";
    }
}

interface NewPaymentInterface {
    public function processPayment();
}

class PaymentAdapter implements NewPaymentInterface {
    private $oldSystem;

    public function __construct(OldPaymentSystem $oldSystem) {
        $this->oldSystem = $oldSystem;
    }

    public function processPayment() {
        return $this->oldSystem->pay(); // We adapt the old method to the new system.
    }
}

// Usage
$oldPayment = new OldPaymentSystem();
$adapter = new PaymentAdapter($oldPayment);
echo $adapter->processPayment();
```
[BACK TO THE GUIDE](/en/posts/design-patterns/)

