The poster did not say that the static var has to be - public.

I use static vars (as singleton) in combination with a static accessor
Method (GetInstance()). No public method.


Regards

Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)

-----Original Message-----
From: Stefan Holdermans [mailto:[EMAIL PROTECTED]] 
Sent: Samstag, 8. Juni 2002 17:50
To: [EMAIL PROTECTED]
Subject: Re: [ADVANCED-DOTNET] Singleton pattern

Frank,

(Sorry, I'm way late with this reply... I took a few days off and
actually
enjoyed other things than coding and thinking about it... ;))

On Thu, 6 Jun 2002 08:06:13 -0700, Frank Hileman
<[EMAIL PROTECTED]> wrote:

>Regarding static var for singleton: I found that static vars are not
>initialized until the first time you use the class. If you don't use
the
>class, they are never initialized. So your one argument against using a
>static var is refuted. As another poster pointed out, your code is not
>thread-safe. In the end, the simplest and best approach is the static
var.
>There was an article about the singleton pattern in C# (in MSDN I
think),
>and it came to exactly the same conclusion.

I think some postings in this thread showed us how to get the code
thread
safe...

The main issue is: I really feel bad about public fields, whether they
are
static or non-static... I think that we've been using accessor methods
and -- now -- properties for all those reasons. So why would we throw
away
that now?

--Stefan

You can read messages from the Advanced DOTNET archive, unsubscribe from
Advanced DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to