您的位置:首页 > 其它

设计模式--装饰模式And单例模式

2014-06-06 22:59 204 查看
装饰模式

设计原则: 类应该对扩展开房,对修改关闭



使用时:被装饰者声明的时应该声明为基类应用: 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();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: