Ich würde ja zu 'ner MetaKlasse raten:
Delphi-Quellcode:
type
TAbstractClass = class of TAbstractObject;
TAbstractObject = class(TObject)
protected
procedure AbstractMethod; virtual; abstract;
end;
TConcreteObject = class(TAbstractObject)
protected
procedure AbstractMethod; override;
end;
TFileReader = class(TObject)
private
FItemClass: TAbstractClass;
public
property ItemClass: TAbstractClass read FItemClass write FItemClass;
end;
implementation
procedure TFileReader.ReadFromFile;
begin
// über die Metaklasse können hier beliebige Klassen erstellt werden
FItemClass.Create;
end;
var
aFileReader: TFileReader;
begin
aFileReader := TFileReader.Create;
try
aFileReader.ItemClass := TConcreteObject;
// notwendige Methoden aufrufen
aFileReader.ReadFromFile;
finally
FreeAndNil(aFileReader)
end;
end;
CU mr2