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

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.');
end;

procedure TLight.Open;
begin
Writeln('Light is on.');
end;

end.


2.命令对象
unit uReceiveObject;

interface

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

implementation

{ TLight }

procedure TLight.Off;
begin
Writeln('Light is off.');
end;

procedure TLight.Open;
begin
Writeln('Light is on.');
end;

end.


 
3.命令的请求者
unit uSimpleRemoteWithUndo;

interface

uses
uCommandObject;

type
TSimpleRemoteWithUndo = class(TObject)
private
FOnCommand : TCommand;
FOffCommand : TCommand;
FUndoCommand: TCommand;
public
procedure SetCommand(aOnCommand, aOffCommand: TCommand);
procedure OnButtonWasPressed;
procedure OffButtonWasPressed;
procedure UndoButtonWasPressed;
end;

implementation

{ TSimpleRemoteWithUndo }

procedure TSimpleRemoteWithUndo.OffButtonWasPressed;
begin
FOffCommand.Execute;
FUndoCommand := FOffCommand;
end;

procedure TSimpleRemoteWithUndo.OnButtonWasPressed;
begin
FOnCommand.Execute;
FUndoCommand := FOnCommand;
end;

procedure TSimpleRemoteWithUndo.SetCommand(aOnCommand, aOffCommand: TCommand);
begin
FOnCommand := aOnCommand;
FOffCommand := aOffCommand;
end;

procedure TSimpleRemoteWithUndo.UndoButtonWasPressed;
begin
FUndoCommand.Undo;
end;

end.


 
4.客户端,创建具体的命令
program pSimpleRemoteWithUndoTest;

{$APPTYPE CONSOLE}

uses
uSimpleRemoteWithUndo in 'uSimpleRemoteWithUndo.pas',
uCommandObject in 'uCommandObject.pas',
uReceiveObje


相关文档:

DELPHI深度探索 (第2版)PDF电子书

 推荐给大家[url=DELPHI深度探索 (第2版)PDF电子书][/url]
因为需要前几天在网上搜搜过这本书书,可没有,源码倒是有,今天打开经常去的网站,居然发现提供下载了,这个网站自己差不多每天都要打开看看,这几天忙糊涂了,居然没有看到,在这推荐给大家,能下载的,速度很快。
[url=http://www.delphifans.com/Soft ......

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

1.主题与观察者
{《HeadFirst设计模式》之观察者模式 }
{ 主题与观察者 }
{ 编译工具 :Delphi7.0 }
{ 联系方式 :xshlife@163.com }

unit uWeatherReport;

interface

uses
Classes, SysUtils;

type
TObserver = class; { Forward声明,创建两个相 ......

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

      容器的主要职责有两个:存放元素和浏览元素。根据单一职责原则(SRP)要将二者分开,于是将浏览功能打包封装就有了迭代器。
      用迭代器封装对动态数组的遍历:
1.容器中的元素类
{《HeadFirst设计模式》之迭代器模式 }
{ 容器中的元素类 ......

delphi 多态

 什么是多态,字面意思就是“多种形态”,用对象来讲就是子类继承基类,而不同的子类又分别对基类进行功能的扩展。
多态在Object Pascal中是通过虚方法实现的(Virtual Method),在Object Pascal中基类的虚方法是可以被派生类覆盖(Override)的 ......

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

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

unit uStrategy;

interface

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

IFlyBehavior = Interface(IInterface)
procedure Fly;
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号