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

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

1. 命令的接受者
unit uReceiveObject;
interface
type
TLight = class(TObject)
public
procedure Open;
procedure Off;
end;
TGarageDoor = class(TObject)
public
procedure Up;
procedure Down;
procedure Stop;
procedure LightOn;
procedure LightOff;
end;
implementation
{ TLight }
procedure TLight.Off;
begin
Writeln('');
end;
procedure TLight.Open;
begin
Writeln('Light is On.');
end;
{ TGarageDoor }
procedure TGarageDoor.Down;
begin
Writeln('');
end;
procedure TGarageDoor.LightOff;
begin
Writeln('');
end;
procedure TGarageDoor.LightOn;
begin
Writeln('');
end;
procedure TGarageDoor.Stop;
begin
Writeln('');
end;
procedure TGarageDoor.Up;
begin
Writeln('GarageDoor is Open.');
end;
end.

2.命令对象
unit uCommandObject;
interface
uses
uReceiveObject;
type
TCommand = class(TObject)
public
procedure Execute; virtual; abstract;
end;
TLightOnCommand = class(TCommand)
private
FLight: TLight;
public
constructor Create(aLight: TLight);
procedure Execute; override;
end;
TGarageDoorOpenCommand = class(Tcommand)
private
FGarageDoor: TGarageDoor;
public
constructor Create(aGarageDoor: TGarageDoor);
procedure Execute; override;
end;
implementation
{ TLightOnCommand }
constructor TLightOnCommand.Create(aLight: TLight);
begin
FLight := aLight;
end;
procedure TLightOnCommand.Execute;
begin
FLight.Open;
end;
{ TGarageDoorOpenCommand }
constructor TGarageDoorOpenCommand.Create(aGarageDoor: TGarageDoor);
begin
FGarageDoor := aGarageDoor;
end;
procedure TGarageDoorOpenCommand.Execute;
begin
FGarageDoor.Up;
end;
end.

3.命令的请求者即发出者
unit uSimpleRemoteControl;
interface
uses
uCommandObject;
type
TSimpleRemoteControl = class(TObject)
private
FSlot: TCommand;
public
procedure SetCommand(aCommand: TCommand);
procedure ButtonWasPressed;
end;
implementation


相关文档:

delphi 2010 fastMM 内存泄露使用方法

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

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

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

unit uCoffeineBeverageWithHook;

interface

uses
SysUti ......

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

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

unit uComponent;

interface

type
TBeverage = class(TObject) //抽象饮料类
protected
FDescription: String;
public
......

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

1. 复杂的子系统
unit uSubObject;

interface

type

{ TAmplifier与TTuner,TCDPlayer,TDVDPlayer相互依赖。 }
{ 在TTuner等的简单实现时用不到对TAmplifier的引用, }
{ 但现实生活中就应该让TAmplifier提供服务,所以这里保留了。 }
{ TProjector对T ......

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

命令模式可以很轻松的实现撤销(Undo)功能。
1. 命令的接受者
unit uReceiveObject;

interface

type
TLight = class(TObject)
public
procedure Open;
procedure Off;
end;

implementation

{ TLight }

procedure TLight.Off;
begin
Writeln('Light is off.'); ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号