1.1 饿汉模式:静态的,会提前new
package com.apesource.singlton;
public class Hungre {
private static Hungre hungre = new Hungre();
//创建私有构造
public Hungre() {
}
//创建公共方法构造
public static synchronized Hungre crean(){
return hungre;
}
}
1.2 懒汉模式:需要的时候在new
package com.apesource.singlton;
public class Lazy {
private static Lazy lazy = null;
//创建私有构造
public Lazy() {
}
//创建公共方法构造
public static synchronized Lazy crean(){
if(lazy == null){
lazy = new Lazy();
}
return lazy;
}
}
二、工厂模式
package com.apesource.factory;



