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