Re: Singleton



Chris Rolliston wrote:
IMHO, an implementation-specific global variable is
much neater than having a variable const!
A class field makes more sense than either one.

Why, apart from enforcing a .Net framework-style verbosity in both
implementation and use?

1. To reduce the "usage verbosity" you can still have a global function to access the variable (see my other post).

2. A class var is a clean OOP mechanism and it's not .NET specific either. C++ has had class vars for ages now and I always missed them in Delphi 7.

You could even live without ever creating an instance of the class, since the class itself can have data (using class vars). Then you don't have to protect/hide your constructor to avoid misusage.

Taking this approach the usage would only be slidly more verbose:

TSingleton.Somemethod;

instead of

Singleton.Somemethod;

--
Regards
Jens
.