一:为何要使用设计模式?设计模式
---由于设计模式可提升代码的可维护性、可重用性、更容易扩展!ide
二:单例模式函数
1:单例模式之懒汉式spa
代码以下:设计
package com.partten;get
/**it
* @单例模式实现class
* @author zl变量
*扩展
*/
public class Singleton {
//构造函数私有化,保证了外面不能直接建立实例
private Singleton(){}
//定义实例变量
private static Singleton Instance=null;
//没有实例,建立实例
public static Singleton getInstance(){
if(Instance==null){
Instance=new Singleton();
}
return Instance;
}
}
注:这种模式的特色:加载的时候快,运行的时候慢!