Esempio n. 1
0
        public static ICar GetCar(string name)
        {
            ICar car = null;

            switch (name)
            {
            case "bmw":
            {
                car = new Bmw();
                break;
            }

            case "audi":
            {
                car = new Audi();
                break;
            }

            default:
            {
                car = new Ferrari();
                break;
            }
            }
            return(car);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Factory....!");

            Mercedes mercedes = (Mercedes)VehicleFactury.GetVehicle(VehicleName.Mercedes);

            mercedes.run();
            mercedes.start();
            mercedes.stop();

            Bmw bmw = (Bmw)VehicleFactury.GetVehicle(VehicleName.BMW);

            bmw.run();
            bmw.start();
            bmw.stop();
        }
Esempio n. 3
0
        public static IVehicle GetVehicle(string nameClass)
        {
            IVehicle obj = null;

            switch (nameClass)
            {
            case VehicleName.BMW:
                obj = new Bmw();
                break;

            case VehicleName.Mercedes:
                obj = new Mercedes();
                break;

            default:
                obj = new Bmw();
                break;
            }

            return(obj);
        }