We have some legacy code that has a bunch of singletons all over the place (written in C#).
The singleton is a fairly "classic" implementation of the pattern:
public class SomeSingleton
{
private static SomeSingleton instance;
private SomeSingleton()
{
}
public static SomeSingleton Instance
{
get
{
if (instance == null)
{
instance = new SomeSingleton();
}
return instance;
}
}
}
Note that thread safety is not a concern, so no locks are used.
In order to make the code more testable, and without making too many modifications, I'd like to modify this code to delegate the creation of the singleton instance in another class (a factory or similar pattern).
This can assist in creating a "test" instance for testing purposes, or the real version, as it is used now.
Is this a common practice? I could not find any reference to such pattern being used.