用 Delphi 学设计模式(二) 之 工厂方法篇 (原创)[4]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 wlnh_2004 的 blog


//窗体单元文件

unit mainform;

interface

uses
  windows, messages, sysutils, variants, classes, graphics, controls, forms,
  dialogs, stdctrls,factorymethod;

type
  tform1 = class(tform)
    radiobutton1: tradiobutton;
    radiobutton2: tradiobutton;
    radiobutton3: tradiobutton;
    procedure radiobutton3click(sender: tobject);
    procedure radiobutton2click(sender: tobject);
    procedure radiobutton1click(sender: tobject);
  private
    procedure 交易(小贩:接口_小贩);
  end;

var
  form1: tform1;

implementation

{$r *.dfm}


procedure tform1.交易(小贩:接口_小贩);
var
  我买的水果:接口_水果;
begin
    我买的水果:=小贩.工厂();
    showmessage(我买的水果.提示);
    showmessage(我买的水果.被评价);
end;

procedure tform1.radiobutton1click(sender: tobject);
begin
  交易(类_苹果小贩.create);
end;

procedure tform1.radiobutton2click(sender: tobject);
begin
  交易(类_葡萄小贩.create);
end;

procedure tform1.radiobutton3click(sender: tobject);
begin
  交易(类_草莓小贩.create);
end;
end.
  

本文关键:用 Delphi 学设计模式(二) 之 工厂方法篇 (原创)
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top