The singleton
While I agree that a Singleton shouldn’t be used to often, I do want to share my favourite way to implement the singleton pattern for reference.
public class Example
{
private static Example instance;
private Example()
{
// this class cannot get instantiated
}
public static Example getInstance()
{
if (instance == null)
{
instance = new Example();
}
return instance;
}
}