单例模式

来源:互联网 发布:three.js 手机 例子 编辑:程序博客网 时间:2024/06/07 03:01

class Singleton  
{  
private static Singleton singleton = null;  
public static Singleton Instance()  
{  
if (null == singleton)  
singleton = new Singleton();  
return singleton;  
}  
private Singleton()  
{  
}  

定义一个静态的私有变量,通过静态的方法来实例化,首先判断是否已经存在,如果存在就返回已经存在的对象,如果 不存在就实例化

原创粉丝点击