设计模式之我见

设计模式之           创建型模式

一:单身模式

例子:
//与普通类的区别,在于他不使用常规的构造函数来初始化
//而是用 getInstance()的对象实例
public class Singleton
{
private static singleton instance=null;
public static Singleton getlnstance()
{
if(instance==null)
instance=new Singleton();
return instance;
}//我们只能用这种方式来获得对象
//上面的例子比较抽象,如果保证只是产生一个对象我们就要注意Instance==null
}

原文地址:https://www.cnblogs.com/xianqingzh/p/1134415.html