装饰模式
设计原则: 类应该对扩展开房,对修改关闭
使用时:被装饰者声明的时应该声明为基类应用: Component xx = new ConcreteComponent();
被装饰: xx = Decorator(xx);
JAVA 中装饰者模式:
Java。io类
单例模式:
单例模式不多说了:直接上图
解决多线程的措施
在最近学习的Actionscript中,类的构造不能为私有的,所以有点改变,看到晓嘉大神的代码,那个||= 运算符太简练了
private static instance:Xxx;
public function Xxx() {
if (null != instance) {
throw new Eeror("this is a Singleton");
}
}
public function getInstance():Xxx {
return instance||= new Xxx();
}