Exemplo n.º 1
0
        public IDrink CreateDrink(string drinkName, IEnumerable <string> options)
        {
            IDrink drink = GetDrink(drinkName);

            if (drinkName == "Special")
            {
                options = ((SpecialCoffeeAdapter)drink).GetOptions(_specialCoffee).ToList();
            }

            if (drinkName == "Tea")
            {
                ((TeaAdapter)drink).SetTeaBlend(_teaBlend);
            }

            List <string> configurations = options.ToList();

            for (int i = 0; i < configurations.Count; i++)
            {
                switch (configurations[i])
                {
                case "Sugar":
                    drink = new SugarDrinkDecorator(drink, _sugarAmount);
                    break;

                case "Milk":
                    drink = new MilkDrinkDecorator(drink, _milkAmount);
                    break;

                case "Whippedcream":
                    drink = new WhippedcreamDrinkDecorator(drink);
                    break;

                case "Coffee":
                    drink = new CoffeeDrinkDecorator(drink, _drinkStrength);
                    break;

                case "Whiskey":
                    drink = new WiskeyDrinkDecorator(drink);
                    break;

                case "Cointreau":
                    drink = new CointreauDrinkDecorator(drink);
                    break;

                case "Amaretto":
                    drink = new AmarettoDrinkDecorator(drink);
                    break;

                case "Cognac":
                    drink = new CognacDrinkDecorator(drink);
                    break;

                default:
                    drink = new MissingIngrediëntDrinkDecorator(drink);
                    break;
                }
            }

            return(drink);
        }
        public IDrink MixDrink(string name, Amount?sugar = null, Amount?milk = null, Strength?strength = null, TeaBlend?blend = null, CustomCoffee coffee = null)
        {
            // GetValueOrDefault == If not null then use or else use given value
            // Can't seem to get around case? Ask Martijn.
            IDrink drink = null;

            switch (name)
            {
            case "Coffee":
                drink = new StrengthDrinkDecorator(new Coffee(), strength.GetValueOrDefault(Strength.Normal));
                break;

            case "Espresso":
                drink = new StrengthDrinkDecorator(new Espresso(), Strength.Strong);
                break;

            case "Capuccino":
                drink = new StrengthDrinkDecorator(new Capuccino(), Strength.Normal);
                break;

            case "Wiener Melange":
                drink = new StrengthDrinkDecorator(new WienerMelange(), Strength.Weak);
                break;

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

            case "Tea":
                drink = new TeaAdapter(blend.GetValueOrDefault(_defaultTeaBlend));
                break;

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

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

            case "Custom":
                drink = new CustomViewCoffee(coffee);
                break;
            }

            if (sugar != null)
            {
                drink = new SugarDrinkDecorator(drink, sugar.GetValueOrDefault(Amount.Normal));
            }

            if (milk != null)
            {
                drink = new MilkDrinkDecorator(drink, milk.GetValueOrDefault(Amount.Normal));
            }

            return(drink);
        }