易截截图软件、单文件、免安装、纯绿色、仅160KB

Delphi 设计模式:《HeadFirst设计模式》Delphi7代码

模板方法模式定义了一个算法骨架,允许子类对算法的某个或某些步骤进行重写(override)。
1.CoffeineBeverageWithHook
{《HeadFirst设计模式》之模板方法模式 }
{ 编译工具: Delphi7.0 }
{ E-Mail : xshlife@163.com }

unit uCoffeineBeverageWithHook;

interface

uses
SysUtils;

type
TCoffeineBeverageWithHook = class(TObject)
protected
procedure BoilWater;
procedure Brew; virtual; abstract;
procedure PourInCup;
procedure AddCondiments; virtual; abstract;
function CustomerWantsCondiments: Boolean; virtual; { 钩子 }
public
procedure PrepareRecipe; { 模板方法 }
end;

TCoffeeWithHook = class(TCoffeineBeverageWithHook)
private
function GetUserInput: string;
public
procedure Brew; override;
procedure AddCondiments; override;
function CustomerWantsCondiments: Boolean; override;
end;

TTeaWithHook = class(TCoffeineBeverageWithHook)
private
function GetUserInput: string;
public
procedure Brew; override;
procedure AddCondiments; override;
function CustomerWantsCondiments: Boolean; override;
end;

implementation

{ TCoffeineBeverageWithHook }

procedure TCoffeineBeverageWithHook.BoilWater;
begin
Writeln('Boiling Water');
end;

function TCoffeineBeverageWithHook.CustomerWantsCondiments: Boolean;
begin
Result := True;
end;

procedure TCoffeineBeverageWithHook.PourInCup;
begin
Writeln('Poiling into cup');
end;

procedure TCoffeineBeverageWithHook.PrepareRecipe;
begin
BoilWater;
Brew;
PourInCup;
if CustomerWantsCondiments then
AddCondiments;
end;

{ TCoffeeWithHook }

procedure TCoffeeWithHook.AddCondiments;
begin
Writeln('Add Sugar and Milk');
end;

procedure TCoffeeWithHook.Brew;
begin
Writeln('Drip Coffee Through Filter');
end;

function TCoffeeWithHook.CustomerWantsCondiments: Boolean;
var
Answer: string;


相关文档:

悟透delphi 第三章 多线程

第一章  DELPHI的原子世界
第二章  DELPHI与WIN32时空
第三章  多线程
第四章  接口
第五章  包
第六章  事件与消息
第七章  组织你的模块
第八章  探索数据库
第九章  多层体系结构
第十章  操作界面与操作逻辑
第十一章  面向对象数据库基础
第三章&n ......

悟透delphi 第四章 接口

第一章  DELPHI的原子世界
第二章  DELPHI与WIN32时空
第三章  多线程
第四章  接口
第五章  包
第六章  事件与消息
第七章  组织你的模块
第八章  探索数据库
第九章  多层体系结构
第十章  操作界面与操作逻辑
第十一章  面向对象数据库基础
第四章&n ......

悟透delphi 第八章 探索数据库

第一章  DELPHI的原子世界
第二章  DELPHI与WIN32时空
第三章  多线程
第四章  接口
第五章  包
第六章  事件与消息
第七章  组织你的模块
第八章  探索数据库
第九章  多层体系结构
第十章  操作界面与操作逻辑
第十一章  面向对象数据库基础
 空 ......

Delphi 设计模式:《HeadFirst设计模式》Delphi7代码

1. 产品类
{《HeadFirst设计模式》工厂模式之简单工厂 }
{ 产品类 }
{ 编译工具 :Delphi7.0 }
{ 联系方式 :xshlife@163.com }

unit uProducts;

interface

type
TPizza = class(TObject)
public
procedure Prepare; virt ......

delphi 继承类

 继承是为了表现类与类之间“是一种”关系,是多态存在的基础,继承是面象对象必不可少的基础,只支持封装而不支持继承的语言只能称为“基于对象”(Object-Based)面非面向对象“Object-Oriented”;
Object Pascal只支持单继承,也就是一个派生类只能有一个基类
但可以实现多个接口 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号