码迷,mamicode.com
首页 > Windows程序 > 详细

Delphi 设计模式:《HeadFirst设计模式》Delphi7代码---工厂模式之简单工厂

时间:2017-05-21 12:48:55      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:cut   sep   sign   tpi   rac   title   prepare   pattern   virtual   

简单工厂:工厂依据传进的参数创建相应的产品。

http://www.cnblogs.com/DelphiDesignPatterns/archive/2009/07/24/1530536.html

{《HeadFirst设计模式》工厂模式之简单工厂 }
  3{ 产品类                              }
  4{ 编译工具 :Delphi7.0                 }
  5{ 联系方式 :guzh-0417@163.com         }
  6
  7unit uProducts;
  8
  9interface
 10
 11type
 12  TPizza = class(TObject)
 13  public
 14    procedure Prepare; virtual; abstract;
 15    procedure Bake; virtual; abstract;
 16    procedure Cut; virtual; abstract;
 17    procedure Box; virtual; abstract;
 18  end;
 19
 20  TCheesePizza = class(TPizza)
 21  public
 22    procedure Prepare; override;
 23    procedure Bake; override;
 24    procedure Cut; override;
 25    procedure Box; override;
 26  end;
 27
 28  TVeggiePizza = class(TPizza)
 29  public
 30    procedure Prepare; override;
 31    procedure Bake; override;
 32    procedure Cut; override;
 33    procedure Box; override;
 34  end;
 35
 36  TClamPizza = class(TPizza)
 37  public
 38    procedure Prepare; override;
 39    procedure Bake; override;
 40    procedure Cut; override;
 41    procedure Box; override;
 42  end;
 43
 44  TPepperoniPizza = class(TPizza)
 45  public
 46    procedure Prepare; override;
 47    procedure Bake; override;
 48    procedure Cut; override;
 49    procedure Box; override;
 50  end;
 51
 52implementation
 53
 54{ TCheesePizza }
 55
 56procedure TCheesePizza.Bake;
 57begin
 58  Writeln(‘烘烤奶油比萨‘);
 59end;
 60
 61procedure TCheesePizza.Box;
 62begin
 63  Writeln(‘将奶油比萨装盒‘);
 64end;
 65
 66procedure TCheesePizza.Cut;
 67begin
 68  Writeln(‘将奶油比萨切成片‘);
 69end;
 70
 71procedure TCheesePizza.Prepare;
 72begin
 73  Writeln(‘准备奶油比萨‘);
 74end;
 75
 76{ TVeggiePizza }
 77
 78procedure TVeggiePizza.Bake;
 79begin
 80  Writeln(‘烘烤素比萨‘);
 81end;
 82
 83procedure TVeggiePizza.Box;
 84begin
 85  Writeln(‘将素比萨装盒‘);
 86end;
 87
 88procedure TVeggiePizza.Cut;
 89begin
 90   Writeln(‘将素比萨切成片‘);
 91end;
 92
 93procedure TVeggiePizza.Prepare;
 94begin
 95  Writeln(‘准备素比萨‘);
 96end;
 97
 98{ TClamPizza }
 99
100procedure TClamPizza.Bake;
101begin
102  Writeln(‘烘烤蛤蛎比萨‘);
103end;
104
105procedure TClamPizza.Box;
106begin
107  Writeln(‘将蛤蛎比萨装盒‘);
108end;
109
110procedure TClamPizza.Cut;
111begin
112   Writeln(‘将蛤蛎比萨切成片‘);
113end;
114
115procedure TClamPizza.Prepare;
116begin
117  Writeln(‘准备蛤蛎比萨‘);
118end;
119
120{ TPepperoniPizza }
121
122procedure TPepperoniPizza.Bake;
123begin
124  Writeln(‘烘烤Pepperoni比萨‘);
125end;
126
127procedure TPepperoniPizza.Box;
128begin
129  Writeln(‘将Pepperoni比萨装盒‘);
130end;
131
132procedure TPepperoniPizza.Cut;
133begin
134   Writeln(‘将Pepperoni比萨切成片‘);
135end;
136
137procedure TPepperoniPizza.Prepare;
begin
 Writeln(‘准备Pepperoni比萨‘);
end;

end.

Delphi 设计模式:《HeadFirst设计模式》Delphi7代码---工厂模式之简单工厂

标签:cut   sep   sign   tpi   rac   title   prepare   pattern   virtual   

原文地址:http://www.cnblogs.com/Siegel/p/6884265.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!