Glossary

Adapter Pattern

Adapter is a wrapper pattern that converts one class's interface into the interface expected by the client. It lets two incompatible interfaces work together without changing their code.

Example

// Third-party logging library with its own interface
class ThirdPartyLogger {
  public function writeLog(string $level, string $msg): void {}
}

// Our interface
interface Logger {
  public function log(string $msg): void;
}

// Adapter — bridge between them
class LoggerAdapter implements Logger {
  public function __construct(private ThirdPartyLogger $lib) {}
  public function log(string $msg): void {
    $this->lib->writeLog('info', $msg);
  }
}

Classic uses