Exemplo n.º 1
0
        static void Main(string[] args)
        {
            /*
             * Aqui creamos las bebidas para adicionarlas con los decoradores
             * entra a la clase Espresso para analizarla
             */
            IBeverage beverage = new Espresso();

            Console.WriteLine(beverage.Description() + " $ " + beverage.Cost());
            IBeverage beverage2 = new DarckRoast();

            /*
             * Aqui agregamos aditamentos a las bebidas
             * Entra  a la clase Mocha para analizar como
             * es que se agrega la funcionalidad
             */
            beverage2 = new Mocha(beverage2);
            beverage2 = new Mocha(beverage2);
            beverage2 = new Whip(beverage2);
            Console.WriteLine(beverage2.Description() + " $ " + beverage2.Cost());

            IBeverage beverage3 = new HouseBlend();

            beverage3 = new Soy(beverage3);
            beverage3 = new Mocha(beverage3);
            beverage3 = new Whip(beverage3);
            Console.WriteLine(beverage3.Description() + " $ " + beverage3.Cost());
            Console.ReadLine();
        }
Exemplo n.º 2
0
 static void Main(string[] args)
 {
     Beverage beverage = new DarkRoast();
     beverage = new MilkShot(beverage);
     beverage = new Mocha(beverage);
     Console.WriteLine(string.Format("{0}: {1}", beverage.GetDescription(), beverage.GetCost()));
 }
Exemplo n.º 3
0
        private static Beverage ApplyCondiment(List <CONDIMENT_TYPE> clist, Beverage item)
        {
            foreach (var c in clist)
            {
                switch (c)
                {
                case CONDIMENT_TYPE.WHIP:
                {
                    item = new Whip(item);
                }
                break;

                case CONDIMENT_TYPE.MOCHA:
                {
                    item = new Mocha(item);
                }
                break;

                case CONDIMENT_TYPE.SOY:
                {
                    item = new Soy(item);
                }
                break;
                }
            }

            return(item);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Beverage beverage = new Espresso();

            Console.WriteLine(beverage.getDescription()
                              + " $" + beverage.cost());

            Beverage beverage2 = new DarkRoast();

            beverage2 = new Mocha(beverage2);
            beverage2 = new Mocha(beverage2);
            beverage2 = new Whip(beverage2);
            Console.WriteLine(beverage2.getDescription()
                              + " $" + beverage2.cost());

            Beverage beverage3 = new HouseBlend();

            beverage3 = new Soy(beverage3);
            beverage3 = new Mocha(beverage3);
            beverage3 = new Whip(beverage3);
            Console.WriteLine(beverage3.getDescription()
                              + " $" + beverage3.cost());

            Console.ReadKey();
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            Beverage beverage = new Espresso();

            Console.WriteLine(beverage.GetDescription() + " $" + beverage.Cost());

            Beverage beverage2 = new DarkRoast();

            beverage2.SetSize(Beverage.Size.VENTI);
            beverage2 = new Mocha(beverage2);
            beverage2 = new Mocha(beverage2);
            beverage2 = new Whip(beverage2);

            Console.WriteLine(beverage2.GetDescription() + " $" + beverage2.Cost());

            Beverage beverage3 = new DarkRoast();

            beverage3.SetSize(Beverage.Size.GRANDE);
            beverage3 = new Soy(beverage3);
            beverage3 = new Mocha(beverage3);
            beverage3 = new Whip(beverage3);

            Console.WriteLine(beverage3.GetDescription() + " $" + beverage3.Cost());

            Console.ReadLine();
        }
Exemplo n.º 6
0
        private static void Coffee()
        {
            Beverage beverage = new Espresso();

            Console.WriteLine(beverage.GetDescription() + " $" + beverage.Cost());
            beverage = new Venti(beverage);
            Console.WriteLine(beverage.GetDescription() + " $" + beverage.Cost());

            Beverage beverage2 = new HouseBlend();

            beverage2 = new Mocha(beverage2);
            beverage2 = new Soy(beverage2);
            beverage2 = new Whip(beverage2);
            Console.WriteLine(beverage2.GetDescription() + " $" + beverage2.Cost());
            beverage2 = new Tall(beverage2);
            Console.WriteLine(beverage2.GetDescription() + " $" + beverage2.Cost());

            Beverage beverage3 = new DarkRoast();

            beverage3 = new Mocha(beverage3);
            beverage3 = new Mocha(beverage3);
            beverage3 = new Whip(beverage3);
            Console.WriteLine(beverage3.GetDescription() + " $" + beverage3.Cost());
            beverage3 = new Grande(beverage3);
            Console.WriteLine(beverage3.GetDescription() + " $" + beverage3.Cost());
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            /*
             * Design principle: Classes should be open for extension, but closed for modification.
             *
             * The Decorator Pattern: attaches additional responsabilities to an object dynamically.
             * Decorators provide a flexible alternative to subclassing for extending functionality.
             */

            Beverage beverage = new Expresso();

            Console.WriteLine($"{beverage.GetDescription()} ${beverage.Cost()}");

            Beverage beverage2 = new DarkRoast();

            beverage2 = new Mocha(beverage2);
            beverage2 = new Mocha(beverage2);
            beverage2 = new Whip(beverage2);
            Console.WriteLine($"{beverage2.GetDescription()} ${beverage2.Cost()}");

            Beverage beverage3 = new HouseBlend();

            beverage3 = new Soy(beverage3);
            beverage3 = new Mocha(beverage3);
            beverage3 = new Whip(beverage3);
            Console.WriteLine($"{beverage3.GetDescription()} ${beverage3.Cost()}");

            Console.ReadKey();
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            Beverage beverage = new DarkRoast();

            beverage = new MilkShot(beverage);
            beverage = new Mocha(beverage);
            Console.WriteLine(string.Format("{0}: {1}", beverage.GetDescription(), beverage.GetCost()));
        }
Exemplo n.º 9
0
 public void EspressoCondimentsCost()
 {
     IBeverage beverage = new Espresso();
     beverage = new Mocha(beverage); // add mocha
     beverage = new Mocha(beverage); // add mocha again
     beverage = new Soy(beverage); // add soy too
     Assert.AreEqual<double>(2.79, beverage.Cost());
 }
Exemplo n.º 10
0
 public void MyTestMethod()
 {
     IBeverage beverage = new Espresso();
     beverage = new Mocha(beverage); // add mocha
     beverage = new Mocha(beverage); // add mocha again
     beverage = new Soy(beverage); // add soy too
     Assert.AreEqual<string>("Espresso, Mocha, Mocha, Soy", beverage.Description);
 }
Exemplo n.º 11
0
        public static void Main()
        {
            Console.WriteLine("Cart: ");

            Beverage first  = new Mocha(new DarkRoast());
            Beverage second = new SteamedMilk(new HouseBlend());

            Console.WriteLine($"Order 1: {first.Description}\t\t{first.Cost}");
            Console.WriteLine($"Order 2: {second.Description}\t\t{second.Cost}");
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            Espresso espresso = new Espresso();

            Console.WriteLine(espresso.getDescription() + " Cost: " + espresso.Cost());

            Beverage doubleMochaWhipEspresso = new Mocha(new Mocha(new Whip(espresso)));

            Console.WriteLine(doubleMochaWhipEspresso.getDescription() + " Cost: " + doubleMochaWhipEspresso.Cost());
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            Beverage myEspresso = new Espresso();
            myEspresso = new Mocha(myEspresso);
            myEspresso = new Soy(myEspresso);
            myEspresso = new Whip(myEspresso);

            Console.WriteLine(myEspresso.getDescription() + " " + myEspresso.cost());

            Console.ReadLine();
        }
Exemplo n.º 14
0
        static void Main()
        {
            Beverage houseBlend = new HouseBlend();

            houseBlend.BeverageSize = Beverage.Size.Grande;
            houseBlend = new Soy(houseBlend);
            houseBlend = new Mocha(houseBlend);
            houseBlend = new Mocha(houseBlend);

            WriteLine($"{houseBlend.GetDescription()} : {houseBlend.Cost()}");
        }
Exemplo n.º 15
0
        static void Main(string[] args)
        {
            Beverage beverage = new Espresso();

            beverage = new Mocha(beverage);
            beverage = new Mocha(beverage);
            beverage = new Mocha(beverage);

            Console.WriteLine(beverage.Cost());
            Console.ReadLine();
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            var beverage = new Espresso();

            Console.WriteLine(beverage.GetDescription() + " $" + beverage.Cost());

            Beverage beverage2 = new HouseBlend();

            beverage2 = new Mocha(beverage2);
            Console.WriteLine(beverage2.GetDescription() + " $" + beverage2.Cost());
        }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            Baverage baverage = new HouseBlend();

            Console.WriteLine(baverage.GetDescription() + " " + baverage.cost());

            Baverage baverage2 = new Mocha(baverage);

            Console.WriteLine($"{baverage2.GetDescription()},cost: {baverage2.cost()}");
            Console.Read();
        }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            Coffe coffe = new Expresso();   // Recursion is the fact behind. which keeps track of the encapsulated objects.

            coffe = new Mocha(coffe);       // In this line coffe = Mocha at runtime.
            coffe = new Milk(coffe);        // In this line coffe = Milk  at runtime.
            coffe = new Mocha(coffe);       // In this line coffe = Mocha at runtime.

            Console.WriteLine("Ingredients: " + coffe.GetDescription());
            Console.WriteLine("Total Cost: " + coffe.Cost());
        }
Exemplo n.º 19
0
        static void Main()
        {
            Beverage beverage = new DarkRoast();

            beverage = new Mocha(beverage);
            beverage = new Soy(beverage);
            beverage = new Grande(beverage);
            Console.WriteLine(beverage.GetDescription());
            Console.WriteLine("Total: $" + beverage.Cost());
            Console.ReadKey();
        }
        public void TestOrderHouseBlendWithSoyMochaWhip()
        {
            Beverage beverage = new HouseBlend();

            beverage = new Soy(beverage);
            beverage = new Mocha(beverage);
            beverage = new Whip(beverage);

            string test = $"{beverage.GetDescription()} ${beverage.Cost().ToString("0.00")}";

            Assert.AreEqual(test, "House Blend Coffee, Soy, Mocha, Whip $1.49");
        }
Exemplo n.º 21
0
        static void Main(string[] args)
        {
            Beverage espresso = new Espresso();

            System.Console.WriteLine(espresso.GetDescription() + "   -   " + espresso.Cost());

            Beverage espressoMocha = new Mocha(espresso);

            System.Console.WriteLine(espressoMocha.GetDescription() + "   -   " + espressoMocha.Cost());

            System.Console.ReadLine();
        }
Exemplo n.º 22
0
        static void Main(string[] args)
        {
            Beverage myEspresso = new Espresso();

            myEspresso = new Mocha(myEspresso);
            myEspresso = new Soy(myEspresso);
            myEspresso = new Whip(myEspresso);

            Console.WriteLine(myEspresso.getDescription() + " " + myEspresso.cost());

            Console.ReadLine();
        }
        public void TestOrderDarkRoastWithMochaWhip()
        {
            Beverage beverage = new DarkRoast();

            beverage = new Mocha(beverage);
            beverage = new Mocha(beverage);
            beverage = new Whip(beverage);

            string test = $"{beverage.GetDescription()} ${beverage.Cost().ToString("0.00")}";

            Assert.AreEqual(test, "Dark Roast, Mocha, Mocha, Whip $2.54");
        }
Exemplo n.º 24
0
        /// <summary>
        /// The Decorator Pattern attaches additional
        /// responsibilities to an object dynamically.
        /// Decorators provide a flixible alternative to
        /// subclassing for extending functionality.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            var beverage = new Espresso();

            Console.WriteLine($"{beverage.GetDescription()} $ {beverage.Cost()}");

            Beverage beverage2 = new HouseBlend();

            beverage2 = new Soy(beverage2);
            beverage2 = new Mocha(beverage2);
            beverage2 = new Whip(beverage2);
            Console.WriteLine($"{beverage2.GetDescription()} $ {beverage2.Cost()}");
        }
Exemplo n.º 25
0
        static void Main(string[] args)
        {
            Beverage espresso = new Espresso();
            Console.WriteLine(espresso.getDescription()+ " $" + espresso.cost());

            Beverage houseBlend = new HouseBlend();
            houseBlend = new Mocha(houseBlend);
            houseBlend= new Mocha(houseBlend);
            houseBlend = new Soy(houseBlend);
            Console.WriteLine(houseBlend.getDescription() + " $" + houseBlend.cost());

            Console.ReadLine();
        }
Exemplo n.º 26
0
        static void Main(string[] args)
        {
            IBeverage beverage = new Espresso();

            Console.WriteLine(beverage.getDescription() + " $" + beverage.cost());

            IBeverage beverage2 = new DarkRoast();

            beverage2 = new Mocha(beverage2);
            beverage2 = new Mocha(beverage2);

            Console.WriteLine(beverage2.getDescription() + " $" + beverage2.cost());
        }
Exemplo n.º 27
0
        static void Main(string[] args)
        {
            Beverage espresso = new Espresso();

            Console.WriteLine(espresso);

            Beverage houseBlend = new HouseBlend();

            houseBlend = new Mocha(houseBlend);
            houseBlend = new Mocha(houseBlend);
            houseBlend = new Whip(houseBlend);

            Console.WriteLine(houseBlend);
        }
Exemplo n.º 28
0
        static void Main(string[] args)
        {
            Beverage coffee = new Latte();

            Console.WriteLine("Current coffee is: {0}, cost is {1}.", coffee.GetDescription(), coffee.Cost());

            Beverage latteWithMilk         = new Milk(coffee);
            Beverage latteWithMilkAndMocha = new Mocha(latteWithMilk);

            Console.WriteLine("Current coffee is: {0}, cost is {1}.", latteWithMilkAndMocha.GetDescription(), latteWithMilkAndMocha.Cost());

            Beverage latteWithMilkAndDoubleMocha = new Mocha(latteWithMilkAndMocha);

            Console.WriteLine("Current coffee is: {0}, cost is {1}.", latteWithMilkAndDoubleMocha.GetDescription(), latteWithMilkAndDoubleMocha.Cost());
        }
Exemplo n.º 29
0
        static void Main(string[] args)
        {
            Beverage beverage = new Espresso();

            beverage = new Mocha(beverage);
            Console.WriteLine(beverage.GetDescription() + "$" + beverage.Cost());

            Beverage beverage1 = new HouseBlend();

            beverage1 = new Mocha(beverage1);
            //beverage1 = new Mocha(beverage1);
            //beverage1 = new Soy(beverage1);
            //beverage1 = new Soy(beverage1);
            Console.WriteLine(beverage1.GetDescription() + "$" + beverage1.Cost());
        }
Exemplo n.º 30
0
        static void Main(string[] args)
        {
            Beverage beverage = new Espresso();

            Console.WriteLine(beverage.GetDescription() + " $" + beverage.Cost());

            Beverage beverage2 = new DarkRoast();

            beverage2 = new Mocha(beverage2);
            beverage2 = new Mocha(beverage2);
            beverage2 = new Whip(beverage2);
            Console.WriteLine(beverage2.GetDescription() + " $" + beverage2.Cost());

            Console.ReadKey();
        }
Exemplo n.º 31
0
        static void Main(string[] args)
        {
            Beverage espresso = new Espresso();

            Console.WriteLine(espresso.getDescription() + " $" + espresso.cost());

            Beverage houseBlend = new HouseBlend();

            houseBlend = new Mocha(houseBlend);
            houseBlend = new Mocha(houseBlend);
            houseBlend = new Soy(houseBlend);
            Console.WriteLine(houseBlend.getDescription() + " $" + houseBlend.cost());

            Console.ReadLine();
        }
Exemplo n.º 32
0
        public static void Main(string[] args)
        {
            Beverage beverage = new Esprresso();

            Console.WriteLine(beverage.getDescription() + "$" + beverage.cost());

            Beverage beverage2 = new HouseBlend();

            beverage2 = new Mocha(beverage2);
            beverage2 = new Mocha(beverage2);
            beverage2 = new Whip(beverage2);

            Console.WriteLine(beverage2.getDescription() + "$" + beverage2.cost());

            Console.ReadLine();
        }
Exemplo n.º 33
0
        static void Main(string[] args)
        {
            Console.WriteLine("We have these fabulous drinkings.");

            Beverage espresso    = new Espresso();
            Beverage latte       = new Latte();
            Beverage orangejuice = new OrangeJuice();

            Console.WriteLine($"Espresso : {espresso.Description} \\.{espresso.Cost()}");
            Console.WriteLine($"Latte : {espresso.Description} \\.{latte.Cost()}");
            Console.WriteLine($"OrangeJuice : {espresso.Description} \\.{orangejuice.Cost()}");

            Beverage mochaLatte = new Mocha(new Latte());

            Console.WriteLine($"Mocha Latte : {mochaLatte.Description} \\.{mochaLatte.Cost()}");

            Console.ReadLine();
        }
Exemplo n.º 34
0
        static void Main(string[] args)
        {
            var annasBeverage   = new Sprinkles(new Cappuccino());                   // 6
            var billsBeverage   = new Sprinkles(new Mocha());                        // 5
            var carlsBeverage   = new WhippedCream(new Cappuccino());                // 5
            var davesBeverage   = new WhippedCream(new Mocha());                     // 4
            var erinsBeverage   = new Sprinkles(new WhippedCream(new Cappuccino())); // 7
            var fransBeverage   = new WhippedCream(new Sprinkles(new Cappuccino())); // 7
            var galesBeverage   = new Sprinkles(new WhippedCream(new Mocha()));      // 6
            var henrysBeverage  = new Cappuccino();                                  // 4
            var ivonnesBeverage = new Mocha();                                       // 3

            Beverage[] customerBeverages = { annasBeverage, billsBeverage, carlsBeverage, davesBeverage, erinsBeverage, fransBeverage, galesBeverage, henrysBeverage, ivonnesBeverage };

            foreach (var beverage in customerBeverages)
            {
                Console.WriteLine(beverage.Cost());
            }
        }
Exemplo n.º 35
0
        public static void Main(string[] args)
        {
            Beverage beverage = new Espresso();

            Console.WriteLine(beverage.GetDescription() + " $ " + beverage.Cost());

            Beverage c1 = new DarkRoast();

            c1 = new Mocha(c1);
            c1 = new Mocha(c1);
            c1 = new Whip(c1);
            Console.WriteLine(c1.GetDescription() + " $ " + c1.Cost());

            Beverage b3 = new HouseBlend();

            b3 = new Soy(b3);
            b3 = new Mocha(b3);
            b3 = new Whip(b3);
            Console.WriteLine(b3.GetDescription() + " $ " + b3.Cost());
        }
Exemplo n.º 36
0
        static void Main(string[] args)
        {
            IBeverage coffee = new Espresso();

            Console.WriteLine($"{coffee.Description}: £{coffee.Cost}");

            coffee = new DarkRoast();
            coffee = new Mocha(coffee);
            coffee = new Mocha(coffee);
            coffee = new Whip(coffee);

            Console.WriteLine($"{coffee.Description}: £{coffee.Cost}");

            //or, decorating decorators ...

            coffee = new Vanilla(new Mocha(new Mocha(new DarkRoast())));
            Console.WriteLine($"{coffee.Description}: £{coffee.Cost}");

            Console.ReadKey();
        }