国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

DesignPattern之SimpleFactory

2019-11-18 18:02:38
字體:
供稿:網(wǎng)友
 

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Controls,
  Dialogs, ExtCtrls, ShellAPI, AppEvnts, Forms;
type
  IFruitInterface = interface
    ['{D4557157-5241-4116-AA1E-87F86A884EA9}']
    PRocedure grow();
    procedure harvest();
    procedure plant();
  end;

type
  TApple = class(TComponent, IFruitInterface)
  private
    treeAge: Integer;
  public
    procedure grow();
    procedure harvest();
    procedure plant();
  end;

  TStrwaBerry = class(TComponent, IFruitInterface)
  private
    treeAge: Integer;
  public
    procedure grow();
    procedure harvest();
    procedure plant();
  end;
  TGrape = class(TComponent, IFruitInterface)
  private
    treeAge: Integer;
  public
    procedure grow();
    procedure harvest();
    procedure plant();
  end;

  TFruitGarden = class
  public
    class function GetFruit(const strFruit: string): IFruitInterface;
  end;

implementation
//{$R *.dfm}
procedure TApple.grow();
begin
  showmessage('Apple grow');
end;

procedure TApple.harvest();
begin
  showmessage('Apple harvest');
end;

procedure TApple.plant();
begin
  showmessage('Apple plant');
end;

procedure TStrwaBerry.grow();
begin
  showmessage('StrwaBerry plant');
end;

procedure TStrwaBerry.harvest();
begin
  showmessage('StrwaBerry plant');
end;

procedure TStrwaBerry.plant();
begin
  showmessage('StrwaBerry plant');
end;

procedure TGrape.grow();
begin
  showmessage('Grape plant');
end;

procedure TGrape.harvest();
begin
  showmessage('Grape plant');
end;

procedure TGrape.plant();
begin
  showmessage('Grape plant');
end;

class function TFruitGarden.GetFruit(const strFruit: string): IFruitInterface;
begin
  if strFruit = 'Apple' then
    Result := TApple.create(nil)
  else if strFruit = 'StrawBerry' then
    Result := TStrwaBerry.create(nil)
  else if strFruit = 'Grape' then
    Result := TGrape.create(nil)
  else
    raise Exception.Create('Cannot create ' + strFruit);
end;

end.

//test

  AFruitGarden: TFruitGarden;
  AFruit: IFruitInterface;
begin

  AFruitGarden := TFruitGarden.Create();
  try
    AFruit := AFruitGarden.GetFruit(Edit1.Text);
    AFruit.grow();
  except on FruitError: Exception do
      ShowMessage(FruitError.Message);
  end;

  FreeAndNil(AFruitGarden);
end;


上一篇:自定義的TShockwaveflash

下一篇:DesignPattern之FactoryMethod

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
學(xué)習(xí)交流
熱門圖片

新聞熱點(diǎn)

疑難解答

圖片精選

網(wǎng)友關(guān)注

主站蜘蛛池模板: 岳西县| 右玉县| 临城县| 句容市| 孙吴县| 博野县| 蒲江县| 金门县| 含山县| 陆良县| 崇义县| 广州市| 阜康市| 得荣县| 萨迦县| 黑河市| 闵行区| 扎鲁特旗| 奉贤区| 隆化县| 鹤庆县| 通许县| 辽中县| 大连市| 南岸区| 永安市| 桑日县| 霍州市| 千阳县| 石泉县| 宣汉县| 东宁县| 蒲江县| 汉中市| 筠连县| 庐江县| 土默特左旗| 通化县| 逊克县| 洛南县| 新邵县|