Delphi-Quellcode:
unit Unit9;
interface
uses
SysConst, SysUtils;
type
TAnimator =
class
private
FAllowFree: Boolean;
class var FSingleton: TAnimator;
public
procedure BeforeDestruction;
Override;
procedure Animate();
procedure Stop();
end;
TObjectAnimator =
class helper
for TObject
public
function Animate: TAnimator;
end;
implementation
procedure TAnimator.BeforeDestruction;
begin
if not FAllowFree
then
raise EAccessViolation.Create(SAccessViolationNoArg);
end;
function TObjectAnimator.Animate: TAnimator;
begin
Result := TAnimator.FSingleton;
end;
...
initialization
TAnimator.FSingleton := TAnimator.Create;
finalization
TAnimator.FSingleton.FAllowFree := True;
FreeAndNil(TAnimator.FSingleton);
end.
Du könntest natürlich auch einen indirekten Namespace einführen, in Form von einem Namesprefix, welchen du allen deinen Methoden/Property vorstellst.
Delphi-Quellcode:
type
TObjectAnimator = class helper for TObject
public
procedure AnimateAnimate();
procedure AnimateStop();
end;