Ich verwende Initialization und Finalization, da es im Delphi2007 Class-Constructor und Class-Destructor noch nicht gibt.
Beispiel:
Delphi-Quellcode:
unit MyFactory;
interface
uses
Contnrs;
type
TMyObject =
class abstract(TObject)
end;
TMyClass =
class of TMyObject;
TMyFactory =
class(TObject)
private
class var
FClassList: TClassList;
protected
class procedure Initialize;
class procedure Finalize;
public
class procedure RegisterClass(AClass: TMyClass);
class procedure UnRegisterClass(AClass: TMyClass);
end;
implementation
class procedure TMyFactory.Initialize;
begin
FClassList := TClassList.Create;
end;
class procedure TMyFactory.Finalize;
begin
FClassList.Free;
end;
class procedure TMyFactory.RegisterClass(AClass: TMyClass);
begin
FClassList.Add(AClass);
end;
class procedure TMyFactory.UnRegisterClass(AClass: TMyClass);
begin
FClassList.Remove(AClass);
end;
initialization
TMyFactory.Initialize;
finalization
TMyFactory.Finalize;
end.