Dafür könnte man eine Klassenstruktur nur mit class-Methoden, class-Felder und class-Property schaffen:
Delphi-Quellcode:
type
TEncoder =
class;
TEncoding =
class of TEncoder;
TEncoder =
class()
private
class function GetUTF8: TEncoding;
class function GetANSI: TEncoding;
public
class property UTF8: TEncoding
read GetUTF8;
class property ANSI: TEncoding
read GetANSI;
class function GetBytes(
const Source:
string): TBytes;
virtual;
abstract;
end;
TEncoderUTF8 =
class(TEncoder)
public
class function GetBytes(
const Source:
string): TBytes;
override;
end;
TEncoderANSI =
class(TEncoder)
public
class function GetBytes(
const Source:
string): TBytes;
override;
end;
implementation
class function TEncoder.GetUTF8: TEncodingClass;
begin
Result := TEncoderUTF8;
end;
class function TEncoder.GetANSI: TEncodingClass;
begin
Result := TEncoderANSI;
end;
class function TEncoderUTF8.GetBytes(
const Source:
string): TBytes;
begin
{ToDo: }
end;
class function TEncoderANSI.GetBytes(
const Source:
string): TBytes;
begin
{ToDo: }
end;