Re: Singleton
- From: Jens Mühlenhoff <j.muehlenhoff@xxxxxxxxxxxx>
- Date: Mon, 21 Jan 2008 11:47:29 +0100
Jens Mühlenhoff wrote:
I thought about that a little longer, maybe the Delphi language should add support for a new "singleton" keyword like this:
type
TSingleton = class sealed(TObject) // sealed prevents the constructor check to be circumvented
private
FMyFirstProperty: Integer;
class var FInstance: TSingleton;
public
property MyFirstProperty: Integer read FMyFirstProperty write FMyFirstProperty;
constructor Create; // fires an exception when FInstance <> NIL
procedure MyFirstProcedure;
end;
None of this solutions is perfect, so YMMV.
type
MySingleton = singleton
strice private
FMyFirstProperty: Integer;
public
property MyFirstProperty: Integer read FMyFirstProperty write
FMyFirstProperty;
procedure MyFirstProcedure;
end;
There should be no support for instantiation. You access this singleton by its type name:
MySingleton.MyFirstProcedure;
The only problem that is left is the initialization / finalization issue. I can't think of a clean solution that doesn't involve reference counting or a garbage collector.
--
Regards
Jens
.
- Follow-Ups:
- Re: Singleton
- From: Chris Morgan
- Re: Singleton
- References:
- Singleton
- From: Alan T
- Re: Singleton
- From: Chris Rolliston
- Re: Singleton
- From: Chris Morgan
- Re: Singleton
- From: Craig Stuntz [TeamB]
- Re: Singleton
- From: Chris Rolliston
- Re: Singleton
- From: Jens Mühlenhoff
- Re: Singleton
- From: Chris Rolliston
- Re: Singleton
- From: Jens Mühlenhoff
- Re: Singleton
- From: Chris Rolliston
- Re: Singleton
- From: Jens Mühlenhoff
- Singleton
- Prev by Date: Re: Activation limit reached - Told that I cannot increase the limit
- Next by Date: Re: Kylix once more - imo bad product policy
- Previous by thread: Re: Singleton
- Next by thread: Re: Singleton
- Index(es):