Exemplo n.º 1
0
        // The simple factory method has a big flaw where the factory knows about the
        // concrete class being created, where as the abstract and factory method only know of the interfaces

        // The bmw and audi concrete creation could all be different, as so can use the factory method to
        // centralize the creation so the client only knows about the factory and not the complex creation

        static void Main(string[] args)
        {
            #region Simple Factory

            var carName = args[0];

            SimpleAutoFactory factory = new SimpleAutoFactory();

            IAuto car = factory.CreateInstance(carName);

            car.TurnOn();
            car.TurnOff();

            #endregion

            #region Factory Method

            IAutoFactory autoFactory = LoadFactory();

            IAuto autoCar = autoFactory.CreateAuto();

            car.TurnOn();
            car.TurnOff();

            #endregion
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            string carName = Console.ReadLine();
            IAuto  car     = GetCar(carName);

            car.TurnOn();
            car.TurnOff();
        }
Exemplo n.º 3
0
        public void main(string[] args)
        {
            string carName = args[0];
            IAuto  car     = GetCar(carName);

            car.TurnOn();
            car.TurnOff();
        }
Exemplo n.º 4
0
        private static void RunSimpleFactory(string carName)
        {
            AutoFactory factory = new AutoFactory();
            IAuto       car     = factory.CreateInstance(carName);

            car.TurnOn();
            car.TurnOff();
        }
Exemplo n.º 5
0
        public void TestVersion02(string carName)
        {
            AutoFactory factory = new AutoFactory();

            IAuto car = factory.CreateInstance(carName);

            car.TurnOn();
            car.TurnOff();
        }
        public SimpleFactoryPattern(string carName)
        {
            AutoFactory factory = new AutoFactory();

            IAuto car = factory.CreateInstance(carName);

            car.TurnOff();
            car.TurnOn();
        }
Exemplo n.º 7
0
        private void btnFactory_Click(object sender, EventArgs e)
        {
            //IAutoFactory autoFactory = new BMWFactory();
            IAutoFactory autoFactory = LoadAutoFactory(txtCarType.Text);
            IAuto        car         = autoFactory.CreateAutomobile();

            car.TurnOn();
            car.TurnOff();
        }
        public FactoryMethodPattern(string carName)
        {
            IAutoFactory factory = LoadFactories();

            IAuto car = factory.CreateAutomobile();

            car.TurnOff();
            car.TurnOn();
        }
Exemplo n.º 9
0
        static void Main()
        {
            IAutoFactory autoFactory = LoadFactory();

            IAuto car = autoFactory.CreateAutomobile();

            car.TurnOn();
            car.TurnOff();
        }
        public static void SwitchCaseDemo()
        {
            string carCommand = Console.ReadLine();

            IAuto car = SwichCaseFactory.GetCar(carCommand);

            car.TurnOn();
            car.TurnOff();
        }
Exemplo n.º 11
0
        public void main(string[] args)
        {
            string carName = args[0];

            SimpleFactory factory = new SimpleFactory();
            IAuto         car     = factory.CreateInstance("BMW335Xi");

            car.TurnOn();
            car.TurnOff();
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            string      carName = Console.ReadLine();
            AutoFactory factory = new AutoFactory();
            IAuto       car     = factory.CreateInstance(carName);

            car.TurnOn();
            car.TurnOff();
            Console.ReadLine();
        }
Exemplo n.º 13
0
        static void executeSimpleFactory()
        {
            IAutoFactory autoFactory = new BMWFactory();

            IAuto car = autoFactory.CreateAutomobile();

            car.TurnOn();
            car.TurnOff();
            Console.ReadKey();
        }
Exemplo n.º 14
0
        public static void Main(string[] args)
        {
            IAutoFactory autoFactory = LoadFactory();

            IAuto car = autoFactory.CreateAutomobile();

            car.TurnOn();

            car.TurnOff();
        }
        public static void InitializeReflectionDemo()
        {
            string carCommand = Console.ReadLine();

            AutoFactory factory = new AutoFactory();

            IAuto car = factory.CreateInstance(carCommand);

            car.TurnOn();
            car.TurnOff();
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            string input = ReadInput();

            var factory = VehicleFactory.Build(input);

            IAuto car = factory;

            car.TurnOn();
            car.TurnOff();
        }
Exemplo n.º 17
0
 static void Main(string[] args)
 {
     try{
         IAuto auto = AutoFactory.CreateAutoInstance("Toyota");
         auto.TurnOn();
         auto.TurnOff();
     }
     catch (Exception ex) {
         Console.WriteLine(ex.Message);
     }
 }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            string carName = args[0];

            AutoFactory factory = new AutoFactory();

            IAuto car = factory.CreateInstance(carName);

            car.TurnOn();
            car.TurnOff();
        }
Exemplo n.º 19
0
        static void Main(string[] args)
        {
            IAutoFactory autoFactory = LoadFactory();

            IAuto car = autoFactory.CreateAuto();

            car.TurnOn();
            car.TurnOff();

            Console.ReadLine();
        }
Exemplo n.º 20
0
        static void Main(string[] args)
        {
            Console.Write("Enter car name: ");
            var input = Console.ReadLine();

            AutoFactory factory = new AutoFactory();
            IAuto       car     = factory.CreateInstance(input);

            car.TurnOn();
            car.TurnOff();
        }
Exemplo n.º 21
0
 static void Main(string[] args)
 {
     try{
         IAutoFactory autoFactory = LoadFactory();
         IAuto        auto        = autoFactory.CreateAuto();
         auto.TurnOn();
         auto.TurnOff();
     }
     catch (Exception ex) {
         Console.WriteLine(ex.Message);
     }
 }
        static void Main(string[] args)
        {
            Console.WriteLine("Enter name of car");
            string carName = Console.ReadLine();

            //  string carName = args[0];

            IAuto car = GetCar(carName);

            car.TurnOn();
            car.TurnOff();
        }
Exemplo n.º 23
0
        public void Test_CreateCar()
        {
            // Factory method pattern
            IAutoFactory factory = CreateFactory();
            IAuto        auto    = factory.CreateAuto();

            // Simple factory approach
            //CarFactory manager = new CarFactory(); //NOTE: factory type has to be known by the caller in simple factory approach
            //IAuto auto = manager.CreateInstance("audi");

            auto.TurnOn();
            auto.TurnOff();
        }
Exemplo n.º 24
0
        public static void Main(string[] args)
        {
            var careName = Console.ReadLine();

            AutoFactory factory = new AutoFactory();

            IAuto auto = factory.CreateInstance(careName);

            auto.TurnOn();

            auto.TurnOff();

            Console.ReadLine();
        }
Exemplo n.º 25
0
        static void Main(string[] args)
        {
            string carName = args[0];

            //IAuto car = GetCar(carName);

            AutoFactory factory = new AutoFactory();
            IAuto       car     = factory.CreateInstance(carName);

            car.TurnOn();
            car.TurnOff();

            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Enter name of car");
            string carName = Console.ReadLine();
            //string carName  = args[0];

            AutoFactory factory = new AutoFactory();

            IAuto car = factory.CreateInstance(carName);

            car.TurnOn();
            car.TurnOff();

            Console.ReadLine();
        }
Exemplo n.º 27
0
        static void Main(string[] args)
        {
            string carName = args[0];

            //Caller knows about the concrete factory type here
            //Meaning the caller knows which factory type to be called
            Autofactory factory = new Autofactory();

            IAuto car = factory.CreateInstance(carName);

            car.TurnOn();
            car.TurnOff();

            Console.ReadKey();
        }
Exemplo n.º 28
0
        static void Main()
        {
            IAutoFactory autoFactory = LoadFactory();

            //Caller just delegates the pobject creation to a specific factory
            //which takes the a configuration based approach to decide which factory to return and
            //which in turn decides which concrete class to return
            //Here the factory is known but the creation is centralised to specific factory
            //Also more customized objects can be created.
            IAuto car = autoFactory.CreateAutomobile();

            car.TurnOn();
            car.TurnOff();

            Console.ReadKey();
        }
Exemplo n.º 29
0
        static void Main(string[] args)
        {
            string name = string.Empty;

            if (args.Length > 0)
            {
                name = args[0];
            }
            AutoFactory factory = new AutoFactory();
            IAuto       car     = factory.GetAuto(name);

            //IAuto car = GetCar(name);
            car.TurnOn();
            car.TurnOff();
            Console.ReadKey();
        }
Exemplo n.º 30
0
        static void Main()
        {
            while (true)
            {
                Console.WriteLine("hit enter to create a car...");
                Console.ReadLine();

                IAutoFactory autoFactory = LoadFactory();

                IAuto car = autoFactory.CreateAutomobile();

                var myCar = new BMW328i();

                car.TurnOn();
                car.TurnOff();
            }
        }