initialization
TAnyFactory.
Default.RegisterObj<ICanHandleTiere,THund>('
Hund');
TAnyFactory.
Default.RegisterObj<ICanHandleTiere,TKatze>('
Katze');
TAnyFactory.
Default.RegisterObj<ICanHandleTiere>(
Function : TSchwein
begin
Result := TSchwein.Create('
ImDreck');
end,'
Schwein');
TAnyFactory.
Default.RegisterObj<ICanHandleTiere>(
Function : TVogel
begin
Result := TVogel.Create(TAppGlobal.Factory.Get<boolean>('
Kannfliegen'));
// Externer Parameter
end,'
Vogel');
end.
// Andere Unit...
Uses
MyInterfaces;
// Kein Link zur Implementation
var
Hund,Katze,Schwein,Pinguin : ICanHandleTiere;
begin
Hund := TAnyFactory.
Default.CreateObj<ICanhandleTiere>('
Hund');
TAppGlobal.Factory.SetTo<Boolean>('
Kannfliegen',false);
Pinguin := TAnyFactory.
Default.CreateObj<ICanHandleTiere>('
Vogel');
// oder - Falls nicht klar ist, ob die Implementation schon enthalten ist
if TAnyFactory.
Default.TryCreateObj<ICanHandleTiere>(Katze,'
Katze')
then
Katze.GibLaut;
TAnyFactory.
Default.CallIfExists<ICanHandleTiere>(
Procedure ALöwe : ICanHandleTiere)
begin
ALöwe.GibLaut;
end,'
Löwe');
end;