I just finished reading the article on Exploring The
Singleton Design Pattern on MSDN:
http://www.*-*-*.com/
us/dnbda/html/singletondespatt.asp?frame=true
My question is in regards to the final sample code they
use for a simplified Singleton class.
sealed class SingletonCount
{
public static readonly SingletonCounter Instance =
new SingletonCounter();
private long Count = 0;
private SingletonCount() {}
public long NextValue() { return ++Count; }
Quote:
}
What is the point of creating an internal instance of
itself as opposed to declaring Count and NextValue as
static? As in the following code:
sealed class SingletonCount
{
private static long Count = 0;
private SingletonCount() {}
public static NextValue() { return ++Count; }
Quote:
}
I tested this with a client app and the results appear to
be the same. Also, I launched several client apps and
neither provided the expected behaviour of using the same
instance and keeping the same count between each client
app. Each client app started it's own count and 0 and
incremented from one there on, as opposed to picking up
the count where the last one left off. What gives?
TIA~ PJ