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);
        }
예제 #2
0
        static void Main(string[] args)
        {
            ICoffee coffee = new Espresso();

            coffee = new MilkDecorator(coffee);
            coffee = new SugarDecorator(coffee);

            coffee.GetCoffeeDetails();
            Console.ReadLine();
        }
예제 #3
0
        /// <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);
        }
예제 #4
0
        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);
        }
예제 #5
0
 /// <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;
     }
 }
예제 #6
0
        /// <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;
            }
        }
        //switches and such go here.
        //no dictionary necessary as the unlike in the numberConverter project with a dropdown menu they're selected through buttons..
        //nothing instantiated like in the NUmberConverterFactory, so no constructor. The application does not keep a list of ready drinks.

        public IDrink CreateDrink(String name, Amount milkAmount, Amount sugarAmount, Strength strength, Blend blend)
        {//changed from BaseDrinkDecorator to IDrink due to speciality drinks
            IDrink drink = new Drink(name, milkAmount, sugarAmount, strength, blend);

            //var test = new TeaAdapter(drink);
            //test.getTeaNames();

            switch (name)
            {
            case "Cafe au Lait":
                return(new CafeAuLait(drink));

            case "Capuccino":
                return(new Capuccino(drink));

            case "Coffee":
                return(new Coffee(drink));

            case "Chocolate":
                return(new Chocolate(drink));

            case "Chocolate Deluxe":
                return(new Chocolate(drink, true));

            case "Espresso":
                return(new Espresso(drink));

            case "Irish Coffee":
                drink = new Coffee(drink);
                drink = new IrishCoffee(drink);
                drink = new CreamDecorator(drink);
                drink = new SugarDecorator(drink);
                return(drink);

            case "Italian Coffee":
                drink = new Coffee(drink);
                drink = new ItalianCoffee(drink);
                drink = new CreamDecorator(drink);
                drink = new SugarDecorator(drink);
                return(drink);

            case "Spanish Coffee":
                drink = new Coffee(drink);
                drink = new SpanishCoffee(drink);
                drink = new CreamDecorator(drink);
                drink = new SugarDecorator(drink);
                return(drink);

            case "Tea":
                return(new Tea(drink));

            case "Tea and Milk":
                return(new MilkDecorator(new Tea(drink)));

            case "Wiener Melagne":
                return(new WienerMelange(drink));

            //InvalidArgument would make more sense but that requires some specific package.
            default: throw new InvalidOperationException("Invalid drink name argument argument passed to KoffiemachineDomain.Factories.DrinkFactory.CreateDrink");
            }
        }