Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Forma 1 simple factory");
            MotorFactory motorFactoryMethod = new MotorFactory();
            var          diselMethod        = motorFactoryMethod.CreateInstance(TypeMotor.Disel);

            Console.WriteLine(diselMethod.InyectarCombustible(20));
            var gasolinaMethod = motorFactoryMethod.CreateInstance(TypeMotor.Gasolina);

            Console.WriteLine(gasolinaMethod.InyectarCombustible(10));
            Console.ReadKey();

            Console.WriteLine("Forma 2 Factory Method");
            IMotorFactory motorFactory = ObtenerMotor(TypeMotor.Gasolina);

            IMotor gasolina = motorFactory.CreateInstance();

            Console.WriteLine(gasolina.InyectarCombustible(50));

            IMotor disel = ObtenerMotor(TypeMotor.Disel).CreateInstance();

            Console.WriteLine(disel.InyectarCombustible(540));

            Console.ReadKey();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var motorTypeSelected = "S";

            while (motorTypeSelected != "E")
            {
                Console.WriteLine("What kind of motor you want? (G-Gasoline, D-Diesel, E-Exit)");
                motorTypeSelected = Console.ReadLine();
                MotorFactory motorFactory = null;

                motorFactory = motorTypeSelected switch
                {
                    "G" => new MitsubishiL200GasolineFactory(),
                    "D" => new MitsubishiL200DieselFactory(),
                    _ => new MitsubishiL200DieselFactory()
                };

                var motor = motorFactory.CreateMotor();
                Console.WriteLine($"Motor Type Created: {motor.MotorType}{Environment.NewLine}");
            }
        }
    }