《GOF设计模式》—桥接(BRIDGE)—Delphi源码示例:桥接接口
来源:互联网 发布:外国人多喜欢熊猫知乎 编辑:程序博客网 时间:2024/05/01 03:02
示例:桥接接口
说明:
(1)、定义
将抽象部分与它的实现部分分离,使它们都可以独立地变化。
(2)、结构
抽象类:
Abstraction:定义抽象类的接口。维护一个指向Implementor类型对象的指针。
RefinedAbstraction:扩充由Abstraction定义的接口。
实现类:
Implementor:定义实现类的接口,该接口不一定要与Abstraction的接口完全一致;事实上这两个接口可以完全不同。一般来讲,Implementor接口仅提供基本操作,而Abstraction则定义了基于这些基本操作的较高层次的操作。
ConcreteImplementor:实现Implementor接口并定义它的具体实现。
协作:
Abstraction将client的请求转发给它的Implementor对象。
代码:
unit uBridge;
interface
uses
Dialogs;
type
TImplementor = class;
{抽象类}
TAbstraction = class
private
FImp: TImplementor;
public
constructor Create(AImplementor: TImplementor);
//---
procedure Operation; virtual;
end;
TRefinedAbstraction = class(TAbstraction)
public
procedure Operation; override;
end;
{实现类}
TImplementor = class
procedure OperationImp; virtual; abstract;
end;
TConcreteImplementorA = class(TImplementor)
procedure OperationImp; override;
end;
TConcreteImplementorB = class(TImplementor)
procedure OperationImp; override;
end;
implementation
constructor TAbstraction.Create(AImplementor: TImplementor);
begin
FImp := AImplementor;
end;
procedure TAbstraction.Operation;
begin
FImp.OperationImp;
end;
procedure TConcreteImplementorA.OperationImp;
begin
ShowMessage('ImplementorA');
end;
procedure TConcreteImplementorB.OperationImp;
begin
ShowMessage('ImplementorB');
end;
procedure TRefinedAbstraction.Operation;
begin
inherited;
//---
ShowMessage('Refined');
end;
end.
procedure TForm1.Button1Click(Sender: TObject);
var
AImplementor: TImplementor;
AAbstraction: TAbstraction;
begin
AImplementor := TConcreteImplementorA.Create;
AAbstraction := TRefinedAbstraction.Create(AImplementor);
try
AAbstraction.Operation;
finally
AAbstraction.Free;
AImplementor.Free;
end;
end;
- 《GOF设计模式》—桥接(BRIDGE)—Delphi源码示例:桥接接口
- 《GOF设计模式》—桥接(BRIDGE)—Delphi源码示例:桥接接口
- 《GOF设计模式》—桥接(BRIDGE)—Delphi源码示例:可移植的用户界面
- 《GOF设计模式》—桥接(BRIDGE)—Delphi源码示例:仅有一个Implementor
- 《GOF设计模式》—桥接(BRIDGE)—Delphi源码示例:共享Implementor对象
- 《GOF设计模式》—桥接(BRIDGE)—Delphi源码示例:可移植的用户界面
- 《GOF设计模式》—桥接(BRIDGE)—Delphi源码示例:仅有一个Implementor
- 《GOF设计模式》—桥接(BRIDGE)—Delphi源码示例:共享Implementor对象
- 《GOF设计模式》—桥接(BRIDGE)—Delphi源码示例:创建正确的Implementor对象(参数)
- 《GOF设计模式》—桥接(BRIDGE)—Delphi源码示例:创建正确的Implementor对象(缺省的实现)
- 《GOF设计模式》—桥接(BRIDGE)—Delphi源码示例:创建正确的Implementor对象(参数)
- 《GOF设计模式》—桥接(BRIDGE)—Delphi源码示例:创建正确的Implementor对象(缺省的实现)
- 《GOF设计模式》—适配器(ADAPTER)—Delphi源码示例:适配器接口
- 《GOF设计模式》—组合(COMPOSITE)—Delphi源码示例:组合接口
- 《GOF设计模式》—组合(COMPOSITE)—Delphi源码示例:最大化Component接口
- 《GOF设计模式》—装饰(DECORATOR)—Delphi源码示例:装饰接口
- 《GOF设计模式》—享元(FLYWEIGHT)—Delphi源码示例:享元接口
- 《GOF设计模式》—代理(PROXY)—Delphi源码示例:代理接口
- log4net
- 查询数据库之前把密码md5加密
- 各种进制转换
- js判断邮箱代码格式
- Virtual Piano 自动播放乐谱
- 《GOF设计模式》—桥接(BRIDGE)—Delphi源码示例:桥接接口
- 哈希表(Hashtable)
- 对职场橡皮人Say No(转)
- XP下修正“显示隐藏文件夹及文件”方法
- IT豪门的十二星座传奇(转)
- Open aero effect in win 7
- 一个人的爱情
- 读取项目AssemblyInfo.cs属性值
- 时间格式转换....