建造者模式-Delphi述
2006-02-04 13:46:40 来源:WEB开发网依然是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.
- ››Delphi实现把10进制转换成16进制的函数进制转化
- ››Delphi中将字符串按给定字符分隔(似split函数功能...
- ››Delphi 动态创建窗体,锁定窗口赋值
- ››Delphi 与 VC 共享接口和对象
- ››Delphi图像处理 -- 表面模糊
- ››Delphi之多线程实例
- ››Delphi SelectSingleNode的使用 根据节点属性获取...
- ››Delphi接口详述
- ››delphi 远程调试
- ››Delphi与DirectX之DelphiX(34): TDIB.Lightness()...
- ››模式作用域:初级读本和最佳实践
- ››Delphi Application.MessageBox详解
更多精彩
赞助商链接