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)
        {
            //No Factory
            Console.WriteLine("No Factory");
            Console.WriteLine();
            BMW  bmw  = new BMW();
            Audi audi = new Audi();

            //Factory simple
            SimpleCarFactory factory = new SimpleCarFactory();
            CarStore         store   = new CarStore(factory);

            store.BuyCar("Audi");
        }
Esempio n. 3
0
        internal IAuto CreateInstance(string input)
        {
            IAuto result = null;

            switch (input)
            {
            case "BMW":
                result = new BMW();
                break;

            case "Audi":
                result = new Audi();
                break;

            case "Ferrari":
                result = new Ferrari();
                break;
            }
            return(result);
        }
        public Car CreateCar(string brand)
        {
            Car car = null;

            switch (brand)
            {
            case "Audi":
                car = new Audi();
                break;

            case "BMW":
                car = new BMW();
                break;

            default:
                break;
            }

            return(car);
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            //No Factory
            Console.WriteLine("No Factory");
            Console.WriteLine();
            Audi audi = new Audi();

            audi.BuyCar("A3");

            //Simple factory
            SimpleCarFactory carFactory = new SimpleCarFactory();
            CarStore         store      = new CarStore(carFactory);

            store.BuyCar("Audi", "A3");

            //Factory Method
            CarFactoryMethod audiFactory = new AudiFactory();

            audiFactory.BuyCar("A3");
            CarFactoryMethod bmwFactory = new BMWFactory();

            audiFactory.BuyCar("M3");
        }