Exemplo n.º 1
0
        static void Main(string[] args)
        {
            IAutoMobileFactory f1  = new IAutoMobileFactory();
            IAutoMobile        bmw = f1.make(CarType.bmw);

            bmw.start();
            bmw.stop();
            IAutoMobile audi = f1.make(CarType.audi);

            audi.stop();
            audi.start();
            Console.WriteLine("Case 2:");

            IAutoMobile unspecified = f1.make(CarType.unspecified);

            if (unspecified == null)
            {
                Console.WriteLine("Not available");
            }
            Console.WriteLine("Case 3:");

            IAutoMobile bmw1 = new Bmw();

            bmw1.start();
            bmw1.stop();
            Console.Read();
        }
Exemplo n.º 2
0
        //Simple Factory
        static ICar GetCar(CarName carName)
        {
            ICar car = null;

            switch (carName)
            {
            case CarName.Pride:
                car = new Pride();
                break;

            case CarName.Bmw:
                car = new Bmw();
                break;
            }

            return(car);
        }