设计模式-装饰模式
2014-09-28 01:42
232 查看
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CSharp { class Program { public abstract class Beverage { protected string description = "Unknow Beverage"; virtual public string getDescription() { return description; } public abstract double cost(); } public abstract class CondimentDecorator : Beverage { public abstract override string getDescription(); } public class Espresso : Beverage { public Espresso() { description = "Espresso"; } public override double cost() { return 1.99; } } public class HouseBlend : Beverage { public HouseBlend() { description = "HouseBlend"; } public override double cost() { return 0.89; } } public class Mocha : CondimentDecorator { private Beverage beverage = null; public Mocha(Beverage _beverage) { beverage = _beverage; } public override string getDescription() { return beverage.getDescription() + ", Mocha"; } public override double cost() { return beverage.cost() + 0.20; } } static void Display_Beverage(Beverage beverage) { Console.WriteLine("{0} ${1}", beverage.getDescription(), beverage.cost()); } public static void Test() { Beverage beverage1 = new Espresso(); Display_Beverage(beverage1); Beverage beverage2 = new Mocha(beverage1); Display_Beverage(beverage2); } static void Main(string[] args) { Test(); } } }
相关文章推荐
- 设计模式---装饰模式
- 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)