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

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

 1.策略类
{《HeadFirst设计模式》之策略模式 }
{ 本单元中的类为策略类 }
{ 编译工具: Delphi7.0 }
{ E-Mail : xshlife@163.com }

unit uStrategy;

interface

type
{飞行接口,及其实现类 }

IFlyBehavior = Interface(IInterface)
procedure Fly;
end;

TFlyWithWings = class(TInterfacedObject, IFlyBehavior)
public
procedure Fly;
end;

TFlyNoWay = class(TInterfacedObject, IFlyBehavior)
public
procedure Fly;
end;

TFlyRocketPowered = class(TInterfacedObject, IFlyBehavior)
public
procedure Fly;
end;

{叫声接口,及其实现类}

IQuackBehavior = Interface(IInterface)
procedure Quack;
end;

TQuack = class(TInterfacedObject, IQuackBehavior)
public
procedure Quack;
end;

TMuteQuack = class(TInterfacedObject, IQuackBehavior)
public
procedure Quack;
end;

TSqueak = class(TInterfacedObject, IQuackBehavior)
public
procedure Quack;
end;

implementation

{ TFlyWithWings }

procedure TFlyWithWings.Fly;
begin
Writeln('I am flying!');
end;

{ TFlyNoWay }

procedure TFlyNoWay.Fly;
begin
Writeln('I can not fly!');
end;

{ TFlyRocketPowered }

procedure TFlyRocketPowered.Fly;
begin
Writeln('I am flying with a rocket!');
end;

{ TQuack }

procedure TQuack.Quack;
begin
Writeln('Quack');
end;

{ TMuteQuack }

procedure TMuteQuack.Quack;
begin
Writeln('<Silence>');
end;

{ TSqueak }

procedure TSqueak.Quack;
begin
Writeln('Squeak');
end;

end.

2.策略的用户
  {《HeadFirst设计模式》之策略模式 }
{ 本单元中的类为策略的用户, }
{ 一般策略模式中的上下文接口已包含在用户类中。}
{ 编译工具: Delphi7.0 }
{ E-Mail : xshlife@163.com }

unit uDuck;

interface

uses
uStrategy;

type
{ 鸭子抽象类 }

TDuck


相关文档:

delphi 2010 fastMM 内存泄露使用方法

Delphi2010集成了fastMM,这回大家调试程序是的时候可以方便地检查内存泄露了。
使用方法如下:
在project中,添加一行 ReportMemoryLeaksOnShutdown := DebugHook<>0;
DebugHook<>0 目的是保证单独运行exe文件不会弹出内存泄露框,源码可以不用注释掉此行
program Project1;
uses
  Forms,
  ......

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

一、一个叫声接口和几只鸭子
1、从一个叫声接口开始
{《HeadFirst设计模式》Delphi代码之模式小结 }
{ 一个叫声接口 }
{ 编译工具:Delphi2010 for win32 }
{ E-Mail :xshlife@163.com }

unit uQuackable;

interface

type
IQuackable = in ......

delphi 友元类

 在一个单元中声明的多个类互为友元类
type
TMyClass = class
GUID: string;
Name: string;
bSex: Boolean;
Tel : string;
end;
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
procedure Button2Click(Sender: TObject);
procedu ......

delphi 继承类

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