public void ShouldHaveDoubleMilkInMilo() { var milo = new MilkDecorator(new Milo()); milo = new MilkDecorator(milo); Assert.AreEqual(3, milo.CalculateCost()); }
internal static void Decorator() { var expressoWithMilkAndChocolate = new MilkDecorator(new ChocolateDecorator(new Expresso())); Console.WriteLine($"The price of {expressoWithMilkAndChocolate.GetDescription()} is {expressoWithMilkAndChocolate.GetCost()}"); DecoratorDemo2(); }
public IDrink CreateDrink(string name, Strength strength, Amount sugarAmount, Amount milkAmount, bool hasSugar, bool hasMilk, string blendname, string special) { IDrink drink = new Drink(name, strength); if (hasSugar) { drink = new SugarDecorator(drink, sugarAmount); } if (hasMilk) { drink = new MilkDecorator(drink, milkAmount); } switch (drink.Name) { case CAFEAULAIT: drink = new CafeAuLaitDecorator(drink); break; case CAPPUCCINO: drink = new CappuccinoDecorator(drink); break; case COFFEE: drink = new CoffeeDrinkDecorator(drink); break; case ESPRESSO: drink = new EspressoDecorator(drink); break; case WIENERMELANGE: drink = new WienerMelangeDecorator(drink); break; case CHOCOLATE: drink = new HotChocolateDecorator(drink, false); break; case DELUXE: drink = new HotChocolateDecorator(drink, true); break; case TEA: drink = new TeaDecorator(drink, blendname); break; case SPECIAL: drink = new SpecialCoffeeDecorator(drink, special); break; } return(drink); }
/// <summary> /// Orders the drink. /// </summary> /// <param name="type">The type.</param> /// <param name="addOn">The add on.</param> /// <returns>IDrink implementation</returns> public static IDrink OrderDrink(DrinkType type, DrinkAddOn addOn) { IDrink drink = null; switch (type) { case DrinkType.Expresso: drink = new Expresso(); break; case DrinkType.Tea: drink = new Tea(); break; case DrinkType.IceTea: drink = new IceTea(); break; default: break; } if (drink != null) { if (type != DrinkType.IceTea) { if (addOn.HasMilk) { drink = new MilkDecorator(drink); } else { drink.Description += " without milk"; } } if (addOn.HasSugar) { drink = new SugarDecorator(drink); } else { drink.Description += " without sugar"; } if (addOn.HasChocolate && type == DrinkType.Expresso) { drink = new ChocolateDecorator(drink); } } drink.Description = $"We are preparing the following drink for you: {drink.Description}"; return(drink); }
public void WrapperTests() { var coffee = new Coffee(); var sugarCoffee = new SugarDecorator(coffee); Assert.AreEqual("Coffee, Sugar", sugarCoffee.Ingredients); var hotChocolate = new HotChocolate(); var milkHotChocolate = new MilkDecorator(hotChocolate); Assert.AreEqual("Chocolate, Milk", milkHotChocolate.Ingredients); }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.A)) { ICoffee coffee = new Espresso(); Debug.Log("Coffee discription and cost: " + coffee.GetDescription() + " $" + coffee.GetCost()); } if (Input.GetKeyDown(KeyCode.S)) { ICoffee coffee = new Filtered(); Debug.Log("Coffee discription and cost: " + coffee.GetDescription() + " $" + coffee.GetCost()); } if (Input.GetKeyDown(KeyCode.D)) { ICoffee coffee = new ChocolateDecorator(new Espresso()); Debug.Log("Coffee discription and cost: " + coffee.GetDescription() + " $" + coffee.GetCost()); } if (Input.GetKeyDown(KeyCode.F)) { ICoffee coffee = new ChocolateDecorator(new Filtered()); Debug.Log("Coffee discription and cost: " + coffee.GetDescription() + " $" + coffee.GetCost()); } if (Input.GetKeyDown(KeyCode.Z)) { ICoffee coffee = new MilkDecorator(new Espresso()); Debug.Log("Coffee discription and cost: " + coffee.GetDescription() + " $" + coffee.GetCost()); } if (Input.GetKeyDown(KeyCode.X)) { ICoffee coffee = new MilkDecorator(new Filtered()); Debug.Log("Coffee discription and cost: " + coffee.GetDescription() + " $" + coffee.GetCost()); } if (Input.GetKeyDown(KeyCode.C)) { ICoffee coffee = new ChocolateDecorator(new MilkDecorator(new Filtered())); Debug.Log("Coffee discription and cost: " + coffee.GetDescription() + " $" + coffee.GetCost()); } if (Input.GetKeyDown(KeyCode.V)) { ICoffee coffee = new ChocolateDecorator(new MilkDecorator(new Espresso())); Debug.Log("Coffee discription and cost: " + coffee.GetDescription() + " $" + coffee.GetCost()); } }
/// <summary> /// Manages the coffee addIns /// </summary> /// <param name="drinkOrder"></param> /// <param name="hasMilk"></param> /// <param name="hasSugar"></param> /// <param name="hasChocolate"></param> /// <returns>IDrink</returns> public static IDrink ProcessCoofeeAddIns(IDrink drinkOrder, bool hasMilk, bool hasSugar, bool hasChocolate) { try { IDrink fullDrink; //in this case every coffee allow every addIns if (hasMilk && hasSugar && hasChocolate) { return(fullDrink = new MilkDecorator(new SugarDecorator(new ChocolateDecorator(drinkOrder)))); } else if (!hasMilk && hasSugar && hasChocolate) { return(fullDrink = new SugarDecorator(new ChocolateDecorator(drinkOrder))); } else if (hasMilk && !hasSugar && hasChocolate) { return(fullDrink = new MilkDecorator(new ChocolateDecorator(drinkOrder))); } if (hasMilk && hasSugar && !hasChocolate) { return(fullDrink = new MilkDecorator(new SugarDecorator(drinkOrder))); } else if (!hasMilk && !hasSugar && hasChocolate) { return(fullDrink = new ChocolateDecorator(drinkOrder)); } else if (hasMilk && !hasSugar && !hasChocolate) { return(fullDrink = new MilkDecorator(drinkOrder)); } else if (!hasMilk && hasSugar && !hasChocolate) { return(fullDrink = new SugarDecorator(drinkOrder)); } else { //drink without addIns return(drinkOrder); } } catch (Exception) { throw; } }
/// <summary> /// Manage the Tea addIns follows some rules /// </summary> /// <param name="drinkOrder"></param> /// <param name="hasMilk"></param> /// <param name="hasSugar"></param> /// <returns></returns> public static IDrink ProcessTeaAddIns(IDrink drinkOrder, bool hasMilk, bool hasSugar) { IDrink fullDrink; try { //IceTea allows just sugar if (drinkOrder.GetType() == typeof(IceTea)) { if (hasSugar) { return(fullDrink = new SugarDecorator(drinkOrder)); } else { return(drinkOrder); } } else { //Tea does not allow Chocolate if (hasMilk && hasSugar) { return(fullDrink = new MilkDecorator(new SugarDecorator(drinkOrder))); } else if (!hasMilk && hasSugar) { return(fullDrink = new SugarDecorator(drinkOrder)); } else if (hasMilk && !hasSugar) { return(fullDrink = new MilkDecorator(drinkOrder)); } else { return(drinkOrder); } } } catch (Exception) { throw; } }
private void Update() { /// <summary> /// Espresso /// </summary> /// <returns></returns> if (Input.GetKeyDown(KeyCode.E)) {//Default Espress ICoffee coff = new CoffeeEspresso(); Debug.Log("New " + coff.GetDescription() + " Cost: " + coff.GetCost().ToString()); } if (Input.GetKeyDown(KeyCode.R)) {//Espress w/milk ICoffee coff = new MilkDecorator(new CoffeeEspresso()); Debug.Log("New " + coff.GetDescription() + " Cost: " + coff.GetCost().ToString()); } if (Input.GetKeyDown(KeyCode.T)) {//Espress w/choc ICoffee coff = new ChocolateDecorator(new CoffeeEspresso()); Debug.Log("New " + coff.GetDescription() + " Cost: " + coff.GetCost().ToString()); } if (Input.GetKeyDown(KeyCode.Y)) {//Espress w/choc & Milk ICoffee coff = new ChocolateDecorator(new MilkDecorator(new CoffeeEspresso())); Debug.Log("New " + coff.GetDescription() + " Cost: " + coff.GetCost().ToString()); } /// <summary> /// Filtered /// </summary> /// <returns></returns> if (Input.GetKeyDown(KeyCode.F)) {//Default Filtered ICoffee coff = new CoffeeFiltered(); Debug.Log("New " + coff.GetDescription() + " Cost: " + coff.GetCost().ToString()); } if (Input.GetKeyDown(KeyCode.G)) {//Filtered w/milk ICoffee coff = new MilkDecorator(new CoffeeFiltered()); Debug.Log("New " + coff.GetDescription() + " Cost: " + coff.GetCost().ToString()); } if (Input.GetKeyDown(KeyCode.H)) {//Filtered w/choc ICoffee coff = new ChocolateDecorator(new CoffeeFiltered()); Debug.Log("New " + coff.GetDescription() + " Cost: " + coff.GetCost().ToString()); } if (Input.GetKeyDown(KeyCode.J)) {//Filtered w/Milk & choc ICoffee coff = new MilkDecorator(new ChocolateDecorator(new CoffeeFiltered())); Debug.Log("New " + coff.GetDescription() + " Cost: " + coff.GetCost().ToString()); } }