Einzelnen Beitrag anzeigen

freimatz

Registriert seit: 20. Mai 2010
1.426 Beiträge
 
Delphi 11 Alexandria
 
#1

Verschachtelte Datenklassen readonly

  Alt 15. Jul 2024, 13:09
Hallo zusammen,
ich habe ein Design-Problem. Extrem vereinfachtes Beispiel:
Ich habe eine Datenklasse, die hat, weils so schön ist, auch ein interface:
Delphi-Quellcode:
  
  ICoreData = interface
    function GetA(): Integer;
    function GetB(): Double;
    procedure SetA(const p_Value: Integer);
    procedure SetB(const p_Value: Double);
    property A: Integer read GetA write SetA;
    property B: Double read GetB write SetB;
  end;

  TCoreData = class(TInterfacedObject, ICoreData)
  strict private
    FA: Integer;
    FB: Double;
    function GetA(): Integer;
    function GetB(): Double;
    procedure SetA(const p_Value: Integer);
    procedure SetB(const p_Value: Double);

  public
    property A: Integer read GetA write SetA;
    property B: Double read GetB write SetB;
  end;
Nun möchte ich die Daten weitergeben, der Empfänger soll da nichts ändern können. Ich mache daher ein Read-Only-Interface.
Delphi-Quellcode:
  ICoreDataReadOnly = interface
    function GetA(): Integer;
    function GetB(): Double;
    property A: Integer read GetA;
    property B: Double read GetB;
  end;

  TCoreData = class(TInterfacedObject, ICoreData, ICoreDataReadOnly)
Soweit so gut.
Nun aber sollen die Daten mit anderen zusammen gepackt werden. Also:
Delphi-Quellcode:
  IKomplexData = interface
    function GetC(): ICoreData;
    function GetD(): string ;
    procedure SetC(const p_Value: ICoreData);
    procedure SetD(const p_Value: string );
    property C: ICoreData read GetC write SetC;
    property D: string read GetD write SetD;
  end;
Das geht auch noch, aber beim Read-Only stehe ich an. Ich hätte das gerne so:
Delphi-Quellcode:
  
  IKomplexDataReadOnly = interface
    ['{059FFBF5-789F-4DFB-9B3C-3F549B4BB0A9}']
    function GetC(): ICoreDataReadOnly;
    function GetD(): string ;
    property C: ICoreDataReadOnly read GetC;
    property D: string read GetD;
  end;
Dann hat das property C zwei verschiedene Typen: einmal ICoreData und einmal ICoreDataReadOnly. Man kann doch aber nur eine implementieren. Ein overload z.B. gibts bei properties ja nicht.
Irgendwelche Ideen?
  Mit Zitat antworten Zitat