设计模式:实际的软件开发,对问题的处理总结经验,设计模式。
23种设计模式
单列设计模式:保证一个类的对象唯一性,私有构造方法,在本类的成员位置,创建出自己类对象。提供公共方法,返回自己创建的对象/
单例模式在java的应用java.lang.Runtime
单例模式之饿汉模式
public class Single{
private Single(){}
private static final Single s=new Single();
public static Single getInstance(){
return s;
}
}
单例模式之懒汉模式
public class Single{
private Single(){}
private static Single s=null;
public static Single getInstance(){
if(s==null){
s=new Single()
return s;
}
}
}