Ejemplo n.º 1
0
        public static void Main()
        {
            var coffee = new Coffee("Filtered");

            coffee.Prepare();


            Console.WriteLine("Making coffee with Milk and Chocolate");
            var customizableDrink = new CustomizableDrink(coffee);

            Milk      milk      = new Milk();
            Chocolate chocolate = new Chocolate();

            customizableDrink.AddExtraIngredient(milk);
            customizableDrink.AddExtraIngredient(chocolate);
            customizableDrink.Prepare();


            Console.WriteLine("Making coffee with Milk");
            var customizableDrink = new CustomizableDrink(coffee);

            customizableDrink.AddExtraIngredient(milk);
            customizableDrink.Prepare();
        }
Ejemplo n.º 2
0
 public Decorator(Coffee coffee)
 {
     this._coffee = coffee;
 }
Ejemplo n.º 3
0
 public override double Cost()
 {
     return(Coffee.Cost() + 0.2);
 }
Ejemplo n.º 4
0
 private static void MyPrint(Coffee coffee)
 {
     Console.WriteLine($"描述={coffee.Desc},费用={coffee.Price}");
 }
Ejemplo n.º 5
0
 public Chocolate(Coffee coffee) : base(coffee)
 {
     this.Desc  = "巧克力";
     this.Price = 1;
 }
Ejemplo n.º 6
0
 public StrongerCoffee(Coffee coffee) : base(coffee.Name + " покрепче", coffee)
 {
 }
Ejemplo n.º 7
0
 public LessStrongCoffee(Coffee coffee) : base(coffee.Name + " менее крепкий", coffee)
 {
 }
Ejemplo n.º 8
0
 /// <summary>
 /// 牛奶
 /// </summary>
 /// <param name="coffee"></param>
 public Milk(Coffee coffee) : base(coffee)
 {
     this.Desc  = "牛奶";
     this.Price = 2;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Определяем ссылку на декорируемый объект при помощи конструктора.
 /// </summary>
 /// <param name="name">Название кофе</param>
 /// <param name="coffee">Ссылка на декорируемый объект</param>
 public CoffeeDecorator(string name, Coffee coffee) : base(name)
 {
     this.coffee = coffee ?? throw new ArgumentException(nameof(coffee));
 }