B
BotRot
Hello Newsgroup,
Constructing a desktop application using C# 2008, .NET Framework 3.5 SP1, and
application files using Access 2007. Briefly the user interface, business layers
and data access-broker layers are constructed in C# (WinForms for the UI). The
application is multiple instancing (MDIParent interface), and the user can
construct application files (called project files) for their purposes.
If the application has a Singleton class with a (general) structure as such;
public sealed class ProjectStore
{
private static volatile ProjectStore instance = null;
private static readonly Object instance_lock = new Object;
// Constructors - Destructor
static ProjectStore()
{
lock(instance_lock)
{
if(instance == null) {instance = new ProjectStore();}
}
}
private ProjectStore() {// Maybe some stuff here}
// Method members a plenty here (non-static of course)
// Field members a plenty here (non-static of course), except for one
public static ProjectStore Instance
{
get {return instance;}
}
} // public sealed class ProjectStore
After reading quite a bit about Singleton classes, and what the above does, there
is one thing I do not understand. If my desktop application is multiple
instancing, is there one instance of my Singleton class for every application
instance? I.e. 3 application instances, hence 3 Singleton instances.
Or, is there only ever one instance of the Singleton for all instances of the
application? I.e. 3 application instances, "share" one Singleton instance
Also as a side note, there are quite a few (more like a lot) of discussions (on
many web pages) on whether the Instance member should be a field like;
public static TheClass Instance {get {return instance;}}
Or a function like;
public static TheClass GetInstance() {return instance;}
Apart from more typing for the field member, does it really matter?
Thank you for your consideration Newsgroup.
Thanks and regards,
- BotRot
Constructing a desktop application using C# 2008, .NET Framework 3.5 SP1, and
application files using Access 2007. Briefly the user interface, business layers
and data access-broker layers are constructed in C# (WinForms for the UI). The
application is multiple instancing (MDIParent interface), and the user can
construct application files (called project files) for their purposes.
If the application has a Singleton class with a (general) structure as such;
public sealed class ProjectStore
{
private static volatile ProjectStore instance = null;
private static readonly Object instance_lock = new Object;
// Constructors - Destructor
static ProjectStore()
{
lock(instance_lock)
{
if(instance == null) {instance = new ProjectStore();}
}
}
private ProjectStore() {// Maybe some stuff here}
// Method members a plenty here (non-static of course)
// Field members a plenty here (non-static of course), except for one
public static ProjectStore Instance
{
get {return instance;}
}
} // public sealed class ProjectStore
After reading quite a bit about Singleton classes, and what the above does, there
is one thing I do not understand. If my desktop application is multiple
instancing, is there one instance of my Singleton class for every application
instance? I.e. 3 application instances, hence 3 Singleton instances.
Or, is there only ever one instance of the Singleton for all instances of the
application? I.e. 3 application instances, "share" one Singleton instance
Also as a side note, there are quite a few (more like a lot) of discussions (on
many web pages) on whether the Instance member should be a field like;
public static TheClass Instance {get {return instance;}}
Or a function like;
public static TheClass GetInstance() {return instance;}
Apart from more typing for the field member, does it really matter?
Thank you for your consideration Newsgroup.
Thanks and regards,
- BotRot