Einzelnen Beitrag anzeigen

Benutzerbild von Sir Rufo
Sir Rufo

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

AW: Design Problem (Shapes)

  Alt 15. Apr 2014, 15:33
Wenn du das flexibel erweitern möchtest, dann nimm eine Shape-Klasse und eine ShapeStrategy-Klasse.
Hier mal skizziert, wie das geht:
Delphi-Quellcode:
type
  TShapeStrategy = class abstract
  protected
    procedure Paint( ACanvas : TCanvas ); virtual; abstract;
  end;

  TShapeStrategyClass = class of TShapeStrategy;

  TShape = class( TGraphicControl )
  private
    FStrategyName : string;
    FStrategy : TShapeStrategy;
    procedure SetStrategyName( const Value : string );
  protected
    procedure Paint; override;
  public
    class procedure RegisterStrategy( const AName : string; AStrategy : TShapeStrategyClass );
  published
    property StrategyName : string read FStrategyName write SetStrategyName;
  end;

procedure TShape.Paint;
begin
  if Assigned( FStrategy ) then
    FStrategy.Paint( Canvas );
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