Thema: Dry-Problem

Einzelnen Beitrag anzeigen

Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#2

AW: Dry-Problem

  Alt 23. Jul 2015, 11:51
Das ist erst mal ein Fall für das Flyweight-Pattern. Damit holst du dir die benötigen Instanzen.

Da du auch noch eine Beschreibung benötigst, wird das Attribut einfach nochmal gekapselt:
Delphi-Quellcode:
type
  TLabeledFlyweight<TIndex,T:class> = class
  private
    FLabel : string;
    FIndex: TIndex;
    FFlyWeight: TFlyWeight<TIndex,T>;
    private GetObject : T;
  public
    public constructor Create( const ALabel: string; AIndex: TIndex; AFlyWeight: TFlyWeight<TIndex,T> );
    property Label: string read FLabel;
    property &Object: string read GetObject;
  end;

function TLabeldFlyweight<TIndex,T>.GetObject : T;
begin
  Result := FFlyweight[FIndex];
end;
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat