Delphi 设计模式:《HeadFirst设计模式》Delphi7代码
1. 命令的接收者
{《HeadFirst设计模式》之命令模式 }
{ 本单元中的类为命令的接收者 }
{ 编译工具 :Delphi7.0 }
{ 联系方式 :xshlife@163.com }
unit uReceiveObject;
interface
type
TLight = class(TObject)
private
FLocation: String;
public
constructor Create(aLocation: String);
procedure Open;
procedure Off;
end;
TCeilingFan = class(TObject)
private
FLevel : Integer;
FLocation: String;
function GetSpeed: Integer;
public
constructor Create(aLocation: String);
procedure High;
procedure Medium;
procedure Low;
procedure Off;
property Speed: Integer read GetSpeed;
end;
TGarageDoor = class(TObject)
private
FLocation: String;
public
constructor Create(aLocation: String);
procedure Up;
procedure Down;
procedure Stop;
procedure LightOn;
procedure LightOff;
end;
TStereo = class(TObject)
private
FLocation: String;
public
constructor Create(aLocation: String);
procedure Play;
procedure Off;
procedure SetCD;
procedure SetDVD;
procedure SetRadio;
procedure SetVolume(aVolume: Integer);
end;
TTV = class(TObject)
private
FLocation: String;
FChannel : Integer;
public
constructor Create(aLocation: String);
procedure Open;
procedure Off;
procedure SetInputChannel;
end;
THottub = class(TObject)
private
FOpen: Boolean;
FTemp: Integer;
function GetTemp: Integer;
procedure SetTemp(const Value: Integer);
public
function Open: Boolean;
function Off : Boolean;
procedure BubblesOpen;
procedure BubblesOff;
procedure JetsOpen;
procedure JetsOff;
procedure Heat;
procedure Cool;
property Temp: Integer read GetTemp write SetTemp;
end;
implementation
const
SPEED_
相关文档:
设置图像关键颜色,使图像的某种或某个范围的颜色成为透明色,是图片合成、动画显示中经常用的图像处理手段。下面是实现代码:
过程定义:
// 设置色键(透明范围)。colorLow 低色键值; colorHigh 高色键值
// 当像素A、R、G、B值同时大于等于colorLow和小于等于colorHigh时为透明色
procedu ......
什么是多态,字面意思就是“多种形态”,用对象来讲就是子类继承基类,而不同的子类又分别对基类进行功能的扩展。
多态在Object Pascal中是通过虚方法实现的(Virtual Method),在Object Pascal中基类的虚方法是可以被派生类覆盖(Override)的 ......
1.策略类
{《HeadFirst设计模式》之策略模式 }
{ 本单元中的类为策略类 }
{ 编译工具: Delphi7.0 }
{ E-Mail : xshlife@163.com }
unit uStrategy;
interface
type
{飞行接口,及其实现类 }
IFlyBehavior = Interface(IInterface)
procedure Fly;
......
1.被装饰者
{《HeadFirst设计模式》之装饰模式 }
{ 本单元中的类为被装饰者 }
{ 编译工具: Delphi7.0 }
{ E-Mail : xshlife@163.com }
unit uComponent;
interface
type
TBeverage = class(TObject) //抽象饮料类
protected
FDescription: String;
public
......