
type
IProductA = interface
function GetName: string;
end;
IProductB = interface
function GetName: string;
end;
//abstract factory
IFactory = interface
function CreateA: IProductA;
function CreateB: IProductB;
end;
TProductA1 = class(TInterfacedObject,
IProductA)
function GetName: string;
end;
TProductB1 = class(TInterfacedObject,
IProductB)
function GetName: string;
end;
//concrete factory 1
TFactory1 = class(TInterfacedObject,
IFactory)
function CreateA: IProductA;
function CreateB: IProductB;
end;
function TProductA1.GetName: string;
begin
Result := 'ProductA1';
end;
function TProductB1.GetName: string;
begin
Result := 'ProductB1';
end;
function TFactory1.CreateA: IProductA;
begin
Result := TProductA1.Create;
end;
function TFactory1.CreateB: IProductB;
begin
Result := TProductB1.Create;
end;
//client works with any factory
procedure Run(const Factory: IFactory);
begin
WriteLn(Factory.CreateA.GetName);
WriteLn(Factory.CreateB.GetName);
end;
begin
Run(TFactory1.Create);
//ProductA1
//ProductB1
end.