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");
        }
示例#2
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);
        }