模式 / 结构模式
image

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

  //existing class with a wrong interface
  TUsSocket = class
  public
    function GetUsPower: string;
  end;

  //class adapter: inherits the adaptee
  //and implements the target
  TSocketAdapter = class(TUsSocket,
    IEuroSocket)
  private
    FRefCount: Integer;
  public
    function GetPower: string;
    function QueryInterface(const IIDTGUID;
      out Obj): HResult; stdcall;
    function _AddRef: Integerstdcall;
    function _Release: Integerstdcall;
  end;

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

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

function TSocketAdapter.QueryInterface(
  const IIDTGUIDout Obj): HResult;
begin
  if GetInterface(IID, Obj) then
    Result := 0
  else
    Result := E_NOINTERFACE;
end;

function TSocketAdapter._AddRefInteger;
begin
  Inc(FRefCount);
  Result := FRefCount;
end;

function TSocketAdapter._ReleaseInteger;
begin
  Dec(FRefCount);
  Result := FRefCount;
end;

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