ÖйúIT¶¯Á¦,×îÐÂ×îÈ«µÄIT¼¼Êõ½Ì³Ì
×îÐÂ100ƪ | ÍÆ¼ö100ƪ | רÌâ100ƪ | ÅÅÐаñ | ËÑË÷ | ÔÚÏßAPIÎĵµ | ÍøÍ¨¾µÏñ
Ê× Ò³ | ³ÌÐò¿ª·¢ | ²Ù×÷ϵͳ | Èí¼þÓ¦Óà| Í¼ÐÎͼÏó | ÍøÂçÓ¦Óà| ¾«ÎÄÜöÝÍ | ½ÌÓýÈÏÖ¤ | Ó²¼þά»¤ | Î´ÕûÀíÆª | Õ¾³¤½Ì³Ì
ASP JS PHP¹¤³Ì ASP.NET ÍøÕ¾½¨Éè UML J2EESUN .NET VC VB VFP ÍøÂçά»¤ Êý¾Ý¿â DB2 SQL2000 Oracle Mysql
·þÎñÆ÷ Win2000 Office C DreamWeaver FireWorks Flash PhotoShop ÉÏÍø±¦µä CorelDraw ЭÒé´óÈ« ÍøÂ簲ȫ ΢ÈíÈÏÖ¤
Ó²¼þά»¤  CPU  Ö÷°å  Ó²ÅÌ  ÄÚ´æ  ÏÔ¿¨  ÏÔʾÆ÷  ¼üÅÌÊó±ê  Éù¿¨ÒôÏä  ´òÓ¡»ú  »úÏäµçÔ´  BIOS  Íø¿¨  C#  Java  Delphi  vs.net2005
  µ±Ç°Î»Öãº> ³ÌÐò¿ª·¢ > ±à³ÌÓïÑÔ > Delphi > ×ÛºÏÎÄÕÂ
DesignPatternÖ®SimpleFactory
×÷Õß:δ֪ ʱ¼ä:2005-07-27 22:01 ³ö´¦:CSDN Ôð±à:chinaitpower
              ÕªÒª£ºDesignPatternÖ®SimpleFactory

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;


¹Ø±Õ±¾Ò³
 
Ê×Ò³ | Ͷ×ÊÓëºÏ×÷ | ·þÎñÌõ¿î | Òþ˽Õþ²ß | Êղر¾Õ¾ | ÉèΪÊ×Ò³ | ÐÂÓû§×¢²á | ÃâÔðÉùÃ÷ | ʹÓðïÖú
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com °æÈ¨ËùÓÐ