摘要: 在系统中,往往有一些服务只需要它们在整个系统中只存在一个实例,而且可以在系统的任意角落访问到它,我们引入单件模式来解决这个问题,这是众多设计模式中的一种class testSingleton{static testSingleton instance;//类的单例private testSingleton{};//构造函数前的修饰符为私有;这样就不能在类的外部用new来生成//一个新的对象public static testSingleton getInstance()//返回 单例{if(instance == null)instance = new testSingleton();retu 阅读全文
posted @ 2012-05-12 10:24 zh yu 阅读(370) 评论(0) 推荐(0) 编辑