Beispiel #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();
        }
Beispiel #2
0
 public Decorator(Coffee coffee)
 {
     this._coffee = coffee;
 }
Beispiel #3
0
 public override double Cost()
 {
     return(Coffee.Cost() + 0.2);
 }
Beispiel #4
0
 private static void MyPrint(Coffee coffee)
 {
     Console.WriteLine($"描述={coffee.Desc},费用={coffee.Price}");
 }
Beispiel #5
0
 public Chocolate(Coffee coffee) : base(coffee)
 {
     this.Desc  = "巧克力";
     this.Price = 1;
 }
Beispiel #6
0
 public StrongerCoffee(Coffee coffee) : base(coffee.Name + " покрепче", coffee)
 {
 }
Beispiel #7
0
 public LessStrongCoffee(Coffee coffee) : base(coffee.Name + " менее крепкий", coffee)
 {
 }
Beispiel #8
0
 /// <summary>
 /// 牛奶
 /// </summary>
 /// <param name="coffee"></param>
 public Milk(Coffee coffee) : base(coffee)
 {
     this.Desc  = "牛奶";
     this.Price = 2;
 }
Beispiel #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));
 }