设计模式之           创建型模式

一:单身模式

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

posted on 2008-04-02 13:17  蚂蚁跳楼  阅读(200)  评论(0编辑  收藏  举报