VS 2008

当我们需要给一个已有的对象动态的附加状态或行为时,使用装饰模式。
装饰模式的要点是:装饰类实现了最初的被装饰类,并且包含了被装饰类的一个实例

1. 模式静态类图

Core Design Patterns(1) Decorator 装饰模式

2. 应用

    从一只可以写的Pen开始
    把它装饰成有颜色的笔、粗线的笔,甚至可以是有颜色且粗线的笔

Core Design Patterns(1) Decorator 装饰模式

IWritable

Core Design Patterns(1) Decorator 装饰模式using System;
Core Design Patterns(1) Decorator 装饰模式
using System.Collections.Generic;
Core Design Patterns(1) Decorator 装饰模式
using System.Linq;
Core Design Patterns(1) Decorator 装饰模式
using System.Text;
Core Design Patterns(1) Decorator 装饰模式
}

Pen

Core Design Patterns(1) Decorator 装饰模式using System;
Core Design Patterns(1) Decorator 装饰模式
using System.Collections.Generic;
Core Design Patterns(1) Decorator 装饰模式
using System.Linq;
Core Design Patterns(1) Decorator 装饰模式
using System.Text;
Core Design Patterns(1) Decorator 装饰模式
}

ColoredPen

Core Design Patterns(1) Decorator 装饰模式using System;
Core Design Patterns(1) Decorator 装饰模式
using System.Collections.Generic;
Core Design Patterns(1) Decorator 装饰模式
using System.Linq;
Core Design Patterns(1) Decorator 装饰模式
using System.Text;
Core Design Patterns(1) Decorator 装饰模式
}

BoldPen

Core Design Patterns(1) Decorator 装饰模式using System;
Core Design Patterns(1) Decorator 装饰模式
using System.Collections.Generic;
Core Design Patterns(1) Decorator 装饰模式
using System.Linq;
Core Design Patterns(1) Decorator 装饰模式
using System.Text;
Core Design Patterns(1) Decorator 装饰模式
}

Client

Core Design Patterns(1) Decorator 装饰模式using System;
Core Design Patterns(1) Decorator 装饰模式
using System.Collections.Generic;
Core Design Patterns(1) Decorator 装饰模式
using System.Linq;
Core Design Patterns(1) Decorator 装饰模式
using System.Text;
Core Design Patterns(1) Decorator 装饰模式
using DesignPattern.Decorator.BLL;
Core Design Patterns(1) Decorator 装饰模式
}

相关文章:

  • 2017-12-13
  • 2021-07-05
  • 2021-10-13
  • 2021-12-11
  • 2022-02-22
猜你喜欢
  • 2021-10-17
  • 2021-12-18
  • 2021-08-14
  • 2021-09-28
  • 2022-12-23
  • 2022-02-06
  • 2021-08-05
相关资源
相似解决方案