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

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

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

unit uItem;

interface

type
TMenuItem = class(TObject)
private
FName: String;
FDescription: String;
FVegetarian : Boolean;
FPrice: Double;
public
constructor Create(aName, aDescription: String;
aVegetarian : Boolean;
aPrice: Double);
function GetName: String;
function GetDescription: String;
function GetPrice: Double;
function IsVegetarian: Boolean;
end;

implementation

{ TMenuItem }

constructor TMenuItem.Create(aName, aDescription: String;
aVegetarian: Boolean;
aPrice: Double);
begin
FName := aName;
FDescription := aDescription;
FVegetarian := aVegetarian;
FPrice := aPrice;
end;

function TMenuItem.GetDescription: String;
begin
Result := FDescription;
end;

function TMenuItem.GetName: String;
begin
Result := FName;
end;

function TMenuItem.GetPrice: Double;
begin
Result := FPrice;
end;

function TMenuItem.IsVegetarian: Boolean;
begin
Result := FVegetarian;
end;

end.

2.迭代器
{《HeadFirst设计模式》之迭代器模式 }
{ 迭代器:封装对容器的遍历 }
{ 编译工具:Delphi7.0 }
{ E-Mail :xshlife@163.com }

unit uIterator;

interface

uses
uItem;

type
TMenuItems = array of TMenuItem;

TIterator = class(TObject)
public
function HasNext: Boolean; virtual; abstract;
function Next : TObject; virtual; abstract;
end;

TDinerMenuIter


相关文档:

Delphi图像处理

    设置图像关键颜色,使图像的某种或某个范围的颜色成为透明色,是图片合成、动画显示中经常用的图像处理手段。下面是实现代码:
过程定义:
// 设置色键(透明范围)。colorLow 低色键值; colorHigh 高色键值
// 当像素A、R、G、B值同时大于等于colorLow和小于等于colorHigh时为透明色
procedu ......

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

1. 抽象工厂的产品
{《HeadFirst设计模式》工厂模式之抽象工厂 }
{ 抽象工厂的产品 }
{ 编译工具:Delphi7.0 }
{ E-Mail :xshlife@163.com }

unit uPizzaIngredient;

interface

type
TDough = class(TObject)
end;

TThinCrustDough ......

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

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

unit uWeatherReport;

interface

uses
Classes, SysUtils;

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

delphi 继承类

 继承是为了表现类与类之间“是一种”关系,是多态存在的基础,继承是面象对象必不可少的基础,只支持封装而不支持继承的语言只能称为“基于对象”(Object-Based)面非面向对象“Object-Oriented”;
Object Pascal只支持单继承,也就是一个派生类只能有一个基类
但可以实现多个接口 ......

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

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

unit uCoffeineBeverageWithHook;

interface

uses
SysUti ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号