建造者模式-Delphi述

<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 728x15, 创建于 08-4-23MSDN */ google_ad_slot = "3624277373"; google_ad_width = 728; google_ad_height = 15; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 160x600, 创建于 08-4-23MSDN */ google_ad_slot = "4367022601"; google_ad_width = 160; google_ad_height = 600; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>

依然是java 与模式里的例子,(java 与模式 闫宏著) 以下是转为Delphi的代码,这次加了注释:)

unit BuilderPattern;

interface

type
  TProduct = class;

  //抽像建造者 规范接口

  TBuilder = class(TObject)
  public
    procedure builderpart1(); virtual; abstract;
    procedure builderpart2(); virtual; abstract;
    function returnProduct(): TProduct; virtual; abstract;
  end;

  //具体的创建者类,组件同他来创建,这样客户端不用知道具体的建造细节

  TConcreteBuilder = class(TBuilder)
  private
    product: TProduct;
  public
    procedure builderpart1(); override;
    procedure builderpart2(); override;
    function returnProduct(): TProduct; override;
  end;

  //产品类

  TProduct = class(TObject)
  //
  end;

  //导演者角色,直接被客户端使用 

 TDirector = class(TObject)
  private
    Builder: TBuilder;
  public
    procedure Initialize();
  end;
implementation

{ TDirector }

procedure TDirector.Initialize;
begin
  Builder := TConcreteBuilder.Create;
  Builder.builderpart1();
  Builder.builderpart2();
  Builder.returnProduct;
end;

{ TConcreteBuilder }

procedure TConcreteBuilder.builderpart1;
begin
  // your code
end;

procedure TConcreteBuilder.builderpart2;
begin
  // your code
end;

function TConcreteBuilder.returnProduct: TProduct;
begin
  Result := product;
end;

end.

<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 728x15, 创建于 08-4-23MSDN */ google_ad_slot = "3624277373"; google_ad_width = 728; google_ad_height = 15; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 160x600, 创建于 08-4-23MSDN */ google_ad_slot = "4367022601"; google_ad_width = 160; google_ad_height = 600; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
阅读更多
个人分类: delphi
上一篇∶开发者的新选择
下一篇性指南
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭