设计模式--装饰模式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();
}
设计原则: 类应该对扩展开房,对修改关闭
使用时:被装饰者声明的时应该声明为基类应用: 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();
}
相关文章推荐
- 设计模式---装饰模式
- NET设计模式之一:装饰模式(Decorator Pattern)
- 设计模式中结构型模式(四)装饰模式(Decorator)
- 设计模式c#描述——装饰(Decorator)模式
- 第四个设计模式:装饰模式
- 设计模式c#语言描述——装饰(Decorator)模式
- 结构型设计模式---Decorator模式(装饰模式)
- .NET设计模式研究之装饰模式
- 解读设计模式----装饰模式(Decorator Pattern)
- 乐在其中设计模式(C#) - 装饰模式(Decorator Pattern)
- 用实例解说Dot Net设计模式——装饰模式
- 第四个设计模式:装饰模式
- AspectJ实现设计模式(七)—装饰模式
- 乐在其中设计模式(C#) - 装饰模式(Decorator Pattern)
- 设计模式之---装饰(decorator)
- 设计模式c#语言描述——装饰(Decorator)模式
- 设计模式之装饰模式篇(Decorator)
- 设计模式之--装饰器模式的硬编码的静态装饰和链化
- 设计模式学习笔记-装饰模式
- 设计模式(11)-装饰模式(Decorator)