模式 / 创建型模式
image

type
  //prototype knows how to copy itself
  TShape = class
  public
    LineCount: Integer;
    Name: string;
    function Clone: TShape;
  end;

function TShape.CloneTShape;
begin
  Result := TShape.Create;
  Result.LineCount := LineCount;
  Result.Name := Name;
end;

var
  Square, Copy: TShape;
begin
  Square := TShape.Create;
  Square.LineCount := 4;
  Square.Name := 'Square';

  Copy := Square.Clone;
  Copy.Name := 'Square copy';

  WriteLn(Square.Name': ',
    Square.LineCount);
  WriteLn(Copy.Name': ', Copy.LineCount);
end.