Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            PopulateCatalogs();

            Recipe recipe = new Recipe();

            recipe.FinalProduct = GetProduct("Café con leche");
            recipe.AddStep(new Step(GetProduct("Café"), 100, GetEquipment("Cafetera"), 120));
            recipe.AddStep(new Step(GetProduct("Leche"), 200, GetEquipment("Hervidor"), 60));
            ConsolePrinter.PrintRecipe(recipe);
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            PopulateCatalogs();

            Recipe recipe = new Recipe();

            recipe.FinalProduct = GetProduct("Café con leche");
            recipe.AddStep(new Step(GetProduct("Café"), 100, GetEquipment("Cafetera"), 120));
            recipe.AddStep(new Step(GetProduct("Leche"), 200, GetEquipment("Hervidor"), 60));
            ConsolePrinter.PrintTicket(recipe);

            /*
             * Café con leche
             * 100 de Café usando 'Cafetera' durante 120
             * 200 de Leche usando 'Hervidor' durante 60
             */
        }
        public static void Main(string[] args)
        {
            PopulateCatalogs();

            Recipe recipe = new Recipe();

            recipe.FinalProduct = GetProduct("Café con leche");
            recipe.AddStep(GetProduct("Café"), 100, GetEquipment("Cafetera"), 120);
            recipe.AddStep(GetProduct("Leche"), 200, GetEquipment("Hervidor"), 60);
            recipe.AddStep("Dejar enfriar", 60);

            IPrinter consolePrinter = new ConsolePrinter();
            IPrinter filePrinter    = new FilePrinter();

            consolePrinter.PrintRecipe(recipe);
            filePrinter.PrintRecipe(recipe);
        }
Ejemplo n.º 4
0
        public static void Main(string[] args)
        {
            Recipe recipe = new Recipe();

            recipe.AddStep("Café", 2, 100, "Cafetera", 10, 1000);
            recipe.AddStep("Leche", 6, 20, "Microondas", 50, 200);

            Product finalProduct = new Product("Café con leche", 20);

            recipe.FinalProduct = finalProduct;

            IPrinter consolePrinter = new ConsolePrinter();
            IPrinter filePrinter    = new FilePrinter();

            filePrinter.PrintRecipe(recipe);
            consolePrinter.PrintRecipe(recipe);
        }
Ejemplo n.º 5
0
        public static void Main(string[] args)
        {
            PopulateCatalogs();

            Recipe recipe = new Recipe();

            recipe.FinalProduct = GetProduct("Café con leche");
            recipe.AddStep(new Step(GetProduct("Café"), 100, GetEquipment("Cafetera"), 120));
            recipe.AddStep(new Step(GetProduct("Leche"), 200, GetEquipment("Hervidor"), 60));

            //Creo 2 objetos del tipo IPrinter uno de ellos es instancia de ConsolePrinter y el otro de FilePrinter

            IPrinter printer1 = new ConsolePrinter();
            IPrinter printer2 = new FilePrinter();

            printer1.PrintRecipe(recipe, printer1);
            printer2.PrintRecipe(recipe, printer2);
        }
Ejemplo n.º 6
0
        public static void Main(string[] args)
        {
            PopulateCatalogs();

            Recipe recipe = new Recipe();

            recipe.FinalProduct = GetProduct("Café con leche");
            recipe.AddStep(new Step(GetProduct("Café"), 100, GetEquipment("Cafetera"), 120));
            recipe.AddStep(new Step(GetProduct("Leche"), 200, GetEquipment("Hervidor"), 60));

            // SE UTILIZA EL PATRON DE POLIMORFISMO

            IPrinter consolePrinter = new ConsolePrinter();
            IPrinter filePrinter    = new FilePrinter();

            consolePrinter.PrintRecipe(recipe);
            filePrinter.PrintRecipe(recipe);
        }
Ejemplo n.º 7
0
        public static void Main(string[] args)
        {
            PopulateCatalogs();

            //Utilizamos Creator para quitar la creación de la instancia Step, en Program,
            //porque es más adecuado que la cree Recipe (mediante el nuevo método AddStep)
            Recipe recipe = new Recipe();

            recipe.FinalProduct = GetProduct("Café con leche");
            recipe.AddStep(GetProduct("Café"), 100, GetEquipment("Cafetera"), 120);
            recipe.AddStep(GetProduct("Leche"), 200, GetEquipment("Hervidor"), 60);

            IPrinter printer;

            printer = new ConsolePrinter();
            printer.PrintRecipe(recipe);
            printer = new FilePrinter();
            printer.PrintRecipe(recipe);
        }
        public static void Main(string[] args)
        {
            PopulateCatalogs();

            Recipe recipe = new Recipe();

            recipe.FinalProduct = GetProduct("Café con leche");
            recipe.AddStep(new Step(GetProduct("Café"), 100, GetEquipment("Cafetera"), 120));
            recipe.AddStep(new Step(GetProduct("Leche"), 200, GetEquipment("Hervidor"), 60));

            /// <summary>
            /// Cambios en el program para poder utilizar las nuevas implementaciones
            /// </summary>
            IPrinter printer;

            printer = new ConsolePrinter();
            printer.PrintRecipe(recipe);
            printer = new FilePrinter();
            printer.PrintRecipe(recipe);
        }
Ejemplo n.º 9
0
        public static void Main(string[] args)
        {
            PopulateCatalogs();

            Recipe recipe = new Recipe();

            recipe.FinalProduct = GetProduct("Café con leche");
            recipe.AddStep(new Step(GetProduct("Café"), 100, GetEquipment("Cafetera"), 120));
            recipe.AddStep(new Step(GetProduct("Leche"), 200, GetEquipment("Hervidor"), 60));

            // Utilizo el principio de sustitucion de Liskov y
            // el patron Polimorfismo
            // el comportamiento de ambos tipos es el esperado
            // ConsolePrinter y FilePrinter por eso cumple el principio de sustitucion
            // Ademas es una solucion polimorfica
            IPrinter printer = new ConsolePrinter();

            printer.PrintRecipe(recipe);
            printer = new FilePrinter();
            printer.PrintRecipe(recipe);
        }
        public static void Main(string[] args)
        {
            // Se crea una clase que será la encargada de instanciar Product y Equipment y guardar en lista.
            CatalogMaker catalog = new CatalogMaker();

            PopulateCatalogs(catalog);
            Recipe recipe = new Recipe();

            recipe.FinalProduct = catalog.GetProduct("Café con leche");

            //Ya no se instancian steps en Program.
            recipe.AddStep(catalog.GetProduct("Café"), 100, catalog.GetEquipment("Cafetera"), 120);
            recipe.AddStep(catalog.GetProduct("Leche"), 200, catalog.GetEquipment("Hervidor"), 60);

            IPrinter printer;

            printer = new ConsolePrinter();
            printer.PrintRecipe(recipe);
            printer = new FilePrinter();
            printer.PrintRecipe(recipe);
        }
        public static void Main(string[] args)
        {
            PopulateCatalogs();

            Recipe recipe = new Recipe();

            recipe.FinalProduct = GetProduct("Café con leche");
            recipe.AddStep(new Step(GetProduct("Café"), 100, GetEquipment("Cafetera"), 120));
            recipe.AddStep(new Step(GetProduct("Leche"), 200, GetEquipment("Hervidor"), 60));

            // Se instancian dos objetos de tipo IPrinter con las dos distintas
            // clases creadas. Luego se las llama de la misma forma obteniendo
            // distintos resultados. Todos ellos, esperados sin interferir.
            // Se concluye que se definió exitosamente la operación polimórfica.

            IPrinter printer1 = new ConsolePrinter();
            IPrinter printer2 = new FilePrinter();

            printer1.PrintRecipe(recipe);
            printer2.PrintRecipe(recipe);
        }
Ejemplo n.º 12
0
        public static void Main(string[] args)
        {
            PopulateCatalogs();

            Recipe recipe = new Recipe();

            recipe.FinalProduct = GetProduct("Café con leche");
            recipe.AddStep(GetProduct("Café"), 100, GetEquipment("Cafetera"), 120);
            recipe.AddStep(GetProduct("Leche"), 200, GetEquipment("Hervidor"), 60);
            recipe.AddStep("Dejar enfriar", 60);

            IPrinter printer;

            printer = new ConsolePrinter();
            printer.PrintRecipe(recipe);
            printer = new FilePrinter();
            printer.PrintRecipe(recipe);

            Console.WriteLine($"Cooked: {recipe.Cooked}");
            recipe.Cook();
            Thread.Sleep(500); // 0.5 segundos
            Console.WriteLine($"Cooked: {recipe.Cooked}");
        }
        public static void Main(string[] args)
        {
            PopulateCatalogs();

            Recipe recipe = new Recipe();

            recipe.FinalProduct = GetProduct("Café con leche");
            recipe.AddStep(new Step(GetProduct("Café"), 100, GetEquipment("Cafetera"), 120));
            recipe.AddStep(new Step(GetProduct("Leche"), 200, GetEquipment("Hervidor"), 60));

            //Se crea una variable del tipo IPrinter para luego asignarle
            // una instancia de ConsolePrinter y otra de FilePrinter.
            //La Operacion PrintTicket es Polimorfica.
            //Cada Clase del Tipo IPrinter tiene la responsabilidad de Imprimir de formas diferentes

            IPrinter printer;

            printer = new ConsolePrinter();
            printer.PrintTicket(recipe);

            printer = new FilePrinter();
            printer.PrintTicket(recipe);
        }
Ejemplo n.º 14
0
        public static void Main(string[] args)
        {
            PopulateCatalogs();

            Recipe recipe = new Recipe();

            recipe.FinalProduct = GetProduct("Café con leche");

            /// <summary>
            /// Se saca la responsabilidad a Program de crear los objetos de tipo Step
            /// y se le asigna a la clase Recipe de acuerdo al patrón Creator,
            /// se detalla en la clase Recipe
            /// </summary>
            /// <returns></returns>
            recipe.AddStep(GetProduct("Café"), 100, GetEquipment("Cafetera"), 120);
            recipe.AddStep(GetProduct("Leche"), 200, GetEquipment("Hervidor"), 60);

            IPrinter printer;

            printer = new ConsolePrinter();
            printer.PrintRecipe(recipe);
            printer = new FilePrinter();
            printer.PrintRecipe(recipe);
        }