unit uFacade;

interface

uses
  SysUtils, Variants, Classes, uObjects;

type
  TFacade = class(TObject)
  private
    obj1Factory : TObj1Factory;
    obj2Factory : TObj2Factory;
    obj3Factory : TObj3Factory;
  public
    function CreateObject1 : TObject1;
    function CreateObject2 : TObject2;
    function CreateObject3 : TObject3;
    Destructor Destroy; override;
  end;
implementation

{ TFacade }

function TFacade.CreateObject1: TObject1;
begin
  if (obj1Factory = nil) then
    obj1Factory := TObj1Factory.Create;
  Result := Obj1Factory.CreateObject1;
end;

function TFacade.CreateObject2: TObject2;
begin
  if (obj2Factory = nil) then
    obj2Factory := TObj2Factory.Create;
  Result := Obj2Factory.CreateObject2;
end;

function TFacade.CreateObject3: TObject3;
begin
  if (obj3Factory = nil) then
    obj3Factory := TObj3Factory.Create;
  Result := Obj3Factory.CreateObject3;
end;

destructor TFacade.Destroy;
begin
  FreeAndNil(Obj1Factory);
  FreeAndNil(Obj2Factory);
  FreeAndNil(Obj3Factory);
  inherited;
end;

end.
 