Esempio n. 1
0
        static void Main(string[] args)
        {
            //All classes, BMW, VW and Audi, implement the same interface. But they each need their own
            //specific construction,and we are using factories to centralize the logic of that construction.
            CarFactory bmwCarFactory = new BMWFactory();
            ICar       bmw           = bmwCarFactory.Order;

            // Go and have some fun with your BMW
            bmw.TurnOn();
            bmw.TurnOff();

            CarFactory audiCarFactory = new AudiFactory();
            ICar       audi           = audiCarFactory.Order;

            // Go and have some fun with your Audi
            audi.TurnOn();
            audi.TurnOff();
        }
Esempio n. 2
0
        public void test()
        {
            Console.Write($"choice car 1 is Benz and 2 is BMW \n");
            string     s   = Console.ReadLine();
            CarFactory cf  = null;
            Car        car = null;

            if (s == "1")
            {
                cf = new BensFactory();
            }
            else
            {
                cf = new BMWFactory();
            }
            car = cf.CreateCar();
            car.StartUp();
            car.Run();
            car.Stop();
            Console.ReadLine();
        }