Example #1
0
        public IDrink CreateDrink(string drinkName, IDictionary <string, Amount> options, Strength strength = 0)
        {
            // Create the Drink
            IDrink drink = null;

            switch (drinkName)
            {
            case "Coffee":
                drink = new Coffee()
                {
                    DrinkStrength = strength
                };
                break;

            case "Espresso":
                drink = new Espresso();
                break;

            case "Capuccino":
                drink = new Capuccino();
                break;

            case "Wiener Melange":
                drink = new WienerMelange();
                break;

            case "Café au Lait":
                drink = new CafeAuLait();
                break;

            case "Chocolate":
                drink = new Chocolate();
                break;

            case "Chocolate Deluxe":
                drink = new ChocolateDeluxe();
                break;

            case "Irish Coffee":
                drink = new IrishCoffee(_configurables[drinkName]);
                break;

            case "Italian Coffee":
                drink = new ItalianCoffee(_configurables[drinkName]);
                break;

            case "Spanish Coffee":
                drink = new SpanishCoffee(_configurables[drinkName]);
                break;
            }

            if (drink != null)
            {
                // Set price using decorators
                foreach (var option in options)
                {
                    switch (option.Key)
                    {
                    case "Sugar":
                        if (drink.CompatibleToppings.Contains("Sugar"))
                        {
                            drink = new SugarDecorator(drink, option.Value);
                        }
                        break;

                    case "Milk":
                        if (drink.CompatibleToppings.Contains("Milk"))
                        {
                            drink = new MilkDecorator(drink, option.Value);
                        }
                        break;
                    }
                }
            }

            return(drink);
        }
        //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");
            }
        }