I am currently writing a program in which about 12 classes need to be a singleton, due to that they are using a messaging service which needs different types. My question is, instead of basically copy and pasting the singleton code for each for creating an instance with only changing the class it makes an instance of. Is there someway to have a common code that is used for the singleton pattern, for any class that needs to create a singleton?
Here is the code to create one of the singletons,
public static void create()
{
if(instance == null)
{
instance = new FooDataWriter();
}
}