装饰设计模式一
2014-07-21 22:53
113 查看
一、概念
当想要对已有的对象进行功能增强时,可以自定义类,将已有对象传入,基于现有的功能,并加强功能。
装饰类通常会通过构造方法接受被修饰的对象。
二、例子
class Person
{
class PersonDemo
{
class SuperPeron{
当想要对已有的对象进行功能增强时,可以自定义类,将已有对象传入,基于现有的功能,并加强功能。
装饰类通常会通过构造方法接受被修饰的对象。
二、例子
class Person
{
public void eat(){
sysout(“I am eating”);
}
}sysout(“I am eating”);
}
class PersonDemo
{
main(){
Person p = new Person();
p.eat();
}
}Person p = new Person();
p.eat();
}
class SuperPeron{
private Person p;
SuperPerson(Person p){
this.p = p;
}
public void superEat(){
sysout(“1.开胃菜”);
sysout(“2.吃饭”);
}
}
SuperPerson(Person p){
this.p = p;
}
public void superEat(){
sysout(“1.开胃菜”);
sysout(“2.吃饭”);
}
相关文章推荐
- 设计模式---装饰模式
- 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)