单例模式 和装饰者模式

高效单例模式
//double check
public class Singleton{
private volatile Singleton instance ;
public Singleton getInstance(){
if(instance == null){
synchorized(Singleton.class){
if(instance == null)
instance = new Singleton();
}
}
}

}

装饰者模式
//被装饰
public class People implments Human{
sayHello(){hello}
}

interface Human{
sayHello();
}
//装饰者
public abstract class decorator implments Human{
Human human;
public decorator(Human human){}
sayHello();
}

public class decorator1 extends decorator{
public decorator(Human human){super(human)}
sayHello(){};
sayGoodbye(){};
}

你可能感兴趣的:(单例模式 和装饰者模式)