Öйú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Ö®FactoryMethod
×÷Õß:δ֪ ʱ¼ä:2005-07-27 22:01 ³ö´¦:CSDN Ôð±à:chinaitpower
              ÕªÒª£ºDesignPatternÖ®FactoryMethod

unit Factory;

interface
uses Windows, Messages, SysUtils, Controls, Product;

type
  IFactoryInterface = interface
    function factory(): IProductInterface;
  end;

  TFactory1 = class(TControl, IFactoryInterface)
  public
    function factory(): IProductInterface;
  end;

  TFactory2 = class(TControl, IFactoryInterface)
  public
    function factory(): IProductInterface;
  end;

implementation

function TFactory1.factory(): IProductInterface;
var
  AProduct: TProduct1;
begin
  AProduct := TProduct1.Create(nil);
  Result := AProduct.CreateProduct();
end;

function TFactory2.factory(): IProductInterface;
var
  AProduct: TProduct2;
begin
  AProduct := TProduct2.Create(nil);
  Result := AProduct.CreateProduct();
end;

end.

unit Product;

interface
uses Windows, Messages, SysUtils, Controls, Dialogs;

type
  IProductInterface = interface
    function CreateProduct(): IProductInterface;
  end;

  TProduct1 = class(TControl, IProductInterface)
  public
    function CreateProduct(): IProductInterface;
  end;
  TProduct2 = class(TControl, IProductInterface)
  public
    function CreateProduct(): IProductInterface;
  end;

implementation

function TProduct1.CreateProduct(): IProductInterface;
begin
  Result := Self;
  showmessage('Product1 Created');
end;

function TProduct2.CreateProduct(): IProductInterface;
begin
  Result := Self;
  showmessage('Product2 Created');
end;


end.

//²âÊÔ

procedure TForm1.Button1Click(Sender: TObject);
var
  AFactory: TFactory1;
begin
  AFactory := TFactory1.Create(Self);
  AFactory.factory;
  FreeAndNil(AFactory);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  AFactory: TFactory2;
begin
  AFactory := TFactory2.Create(Self);
  AFactory.factory;
  FreeAndNil(AFactory);
end;


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