Converts the interface of a class into another interface that a client expects.
Lets incompatible classes work together by wrapping one with a compatible interface.
class EuropeanSocket {
String providePower() => '220V';
}
class USPlugAdapter {
final EuropeanSocket _socket;
USPlugAdapter(this._socket);
String providePower() {
final raw = _socket.providePower();
return '110V (converted from $raw)';
}
}
// Usage
final adapter = USPlugAdapter(EuropeanSocket());
print(adapter.providePower()); // 110V (converted from 220V)