Patterns / Structural patterns
image

type
  //target interface
  IEuroSocket = interface
    function GetPower: string;
  end;

  TUsSocket = class
  public
    function GetUsPower: string;
  end;

  //object adapter: wraps the adaptee
  TSocketAdapter = class(TInterfacedObject,
    IEuroSocket)
  private
    FSocket: TUsSocket;
  public
    constructor Create(Socket: TUsSocket);
    function GetPower: string;
  end;

function TUsSocket.GetUsPowerstring;
begin
  Result := '110V';
end;

constructor TSocketAdapter.Create(
  Socket: TUsSocket);
begin
  FSocket := Socket;
end;

function TSocketAdapter.GetPowerstring;
begin
  Result := FSocket.GetUsPower + as 220V';
end;

var
  Socket: IEuroSocket;
begin
  Socket := TSocketAdapter.Create(
    TUsSocket.Create);
  WriteLn(Socket.GetPower);
  //110V as 220V
end.


Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.