Structural

Adapter

Allows incompatible interfaces to work together.

Legacy code integrationThird-party librariesAPI wrappers

Understanding Adapter

The Adapter pattern allows incompatible interfaces to work together. It wraps an existing class with a new interface, making it compatible with another class without modifying either's source code.

How It Works

Client
expects: Play()
Incompatible!
Adapter
Play() → PlayMP3()
Service
has: PlayMP3()
1

Incompatible Interface

Client expects interface A but service provides interface B.

1 / 4

Basic Implementation

Adapting a legacy MP3 player to a modern interface:

main.go
Loading editor...

Real-World Example: Logger Adapter

Integrating a third-party logging library with your application's interface:

main.go
Loading editor...