單例模式,舉例如下:
class Singleton
{
// Fields
private static Singleton instance;
// Constructor
protected Singleton() {}
// Methods
public static Singleton Instance()
{
if( instance == null )
instance = new Singleton();
return instance;
}
class Singleton
{
// Fields
private static Singleton instance;
// Constructor
protected Singleton() {}
// Methods
public static Singleton Instance()
{
if( instance == null )
instance = new Singleton();
return instance;
}