Ejemplo n.º 1
0
        static void Main(String[] args)
        {
            MercedesFactory mercedesFactory = new MercedesFactory();

            mercedesFactory.ProduceEconomicCar();

            FerrariFactory ferrariFactory = new FerrariFactory();

            ferrariFactory.ProduceLuxuryCar();

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        private static void Main()
        {
            // Create and run the African animal world
            CarFactory   mercedes = new MercedesFactory();
            CarsCreation bendz    = new CarsCreation(mercedes);

            Console.WriteLine(bendz);

            Console.WriteLine();

            CarFactory   BMW    = new BMWFactory();
            CarsCreation beamer = new CarsCreation(BMW);

            Console.WriteLine(beamer);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            CarFactory audiFactory = new AudiFactory();
            var        audiDriver  = new Driver(audiFactory);

            audiDriver.CompareCarTypes();


            CarFactory mercedesFactory = new MercedesFactory();
            var        mercedesDriver  = new Driver(mercedesFactory);

            mercedesDriver.CompareCarTypes();

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Factory mer   = new MercedesFactory();
            Client  merCl = new Client(mer);

            Console.WriteLine("********* MERCEDES **********");
            Console.WriteLine(merCl.GetHeadLightDetails());
            Console.WriteLine(merCl.GetTireDetails());

            Factory aud   = new AudiFactory();
            Client  audCl = new Client(aud);

            Console.WriteLine("********* AUDI **********");
            Console.WriteLine(audCl.GetHeadLightDetails());
            Console.WriteLine(audCl.GetTireDetails());
        }
Ejemplo n.º 5
0
        public static void Main()
        {
            var audiFactory = new AudiFactory();
            var audiDriver  = new Driver(audiFactory);

            audiDriver.CompareSpeed();

            var mercedesFactory = new MercedesFactory();
            var mercedesDriver  = new Driver(mercedesFactory);

            mercedesDriver.CompareSpeed();

            var           factory       = new GenericFactory <AudiSportsCar>();
            AudiSportsCar audiSportsCar = factory.CreateObject();

            Console.WriteLine(audiSportsCar.GetType().ToString());

            Console.ReadLine();
        }
Ejemplo n.º 6
0
        // source код я брав не з методички, а з прикладів на диску
        static void Main(string[] args)
        {
            ICarFactory   carFactory = new ToyotaFactory();
            ClientFactory client1    = new ClientFactory(carFactory);

            client1.Run();

            carFactory = new FordFactory();
            ClientFactory client2 = new ClientFactory(carFactory);

            client2.Run();

            carFactory = new MercedesFactory();
            ClientFactory client3 = new ClientFactory(carFactory);

            client3.Run();

            Console.ReadKey();
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            VehicleFactory vehicleFactory;

            Console.WriteLine("Would you like a (1)Mercedes or a (2)BMW?");
            int brandChoice = Convert.ToInt32(Console.ReadLine());

            if (brandChoice == 1)
            {
                vehicleFactory = new MercedesFactory();
            }
            else if (brandChoice == 2)
            {
                vehicleFactory = new BMWFactory();
            }
            else
            {
                throw new ArgumentException();
            }

            Console.WriteLine("Would you like an (1)Estate car, a (2)SUV or a (3)Convertible?");
            int vehicleTypeChoice = Convert.ToInt32(Console.ReadLine());

            if (vehicleTypeChoice == 1)
            {
                Console.WriteLine("You got a: " + vehicleFactory.CreateEstateCar().GetType().Name);
            }
            else if (vehicleTypeChoice == 2)
            {
                Console.WriteLine("You got a: " + vehicleFactory.CreateSUV().GetType().Name);
            }
            else if (vehicleTypeChoice == 3)
            {
                Console.WriteLine("You got a: " + vehicleFactory.CreateConvertible().GetType().Name);
            }
            else
            {
                throw new ArgumentException();
            }

            Console.ReadLine();
        }
Ejemplo n.º 8
0
        public static void AbstractFactory()
        {
            // Language agnostic version
            CarFactory audiFactory = new AudiFactory();
            Driver     driver1     = new Driver(audiFactory);

            driver1.CompareSpeed();;

            CarFactory mercedesFactory = new MercedesFactory();
            Driver     driver2         = new Driver(mercedesFactory);

            driver2.CompareSpeed();

            // C# specific version using generics
            var factory           = new GenericFactory <MercedesSportsCar>();
            var mercedesSportsCar = factory.CreateObject();

            Console.WriteLine(mercedesSportsCar.GetType().ToString());

            Console.ReadKey();
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            //IMobilePhone nokiaMobilePhone = new Nokia();
            //MobileClient nokiaClient = new MobileClient(nokiaMobilePhone);
            Factory   audiFac    = new AudiFactory();
            CarClient audiClient = new CarClient(audiFac);

            Console.WriteLine("********* AUDI**********");
            Console.WriteLine(audiClient.GetHeadLightDetails());
            Console.WriteLine(audiClient.GetTireDetails());


            Factory   mercedesFac    = new MercedesFactory();
            CarClient mercedesClient = new CarClient(mercedesFac);


            Console.WriteLine("*********MERCEDES**********");
            Console.WriteLine(mercedesClient.GetHeadLightDetails());
            Console.WriteLine(mercedesClient.GetTireDetails());

            Console.ReadKey();
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            /*
             * More info: https://en.wikipedia.org/wiki/Abstract_factory_pattern
             * https://csharpdesignpatterns.codeplex.com/wikipage?title=Abstract%20Factory%20Pattern&referringTitle=Home
             * The Abstract Factory design pattern solves problems like:
             *
             *  How can an application be independent of how its objects are created?
             *  How can a class be independent of how the objects it requires are created?
             *  How can families of related or dependent objects be created?
             *
             * Creating objects directly within the class that requires the objects is inflexible because it commits
             * the class to particular objects and makes it impossible to change the instantiation later independently
             * from (without having to change) the class. It stops the class from being reusable if other objects are required,
             * and it makes the class hard to test because real objects can't be replaced with mock objects.
             */


            CarFactory audiFactory = new AudiFactory();
            Driver     driver1     = new Driver(audiFactory);

            driver1.CompareSpeed();

            CarFactory mercedesFactory = new MercedesFactory();
            Driver     driver2         = new Driver(mercedesFactory);

            driver2.CompareSpeed();


            var factory           = new GenericFactory <MercedesSportsCar>();
            var mercedesSportsCar = factory.CreateObject();

            Console.WriteLine(mercedesSportsCar.GetType().ToString());

            Console.ReadKey();
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            ICarFactory carFactory = new ToyotaFactory();
            Car         myCar      = carFactory.CreateCar();

            myCar.Info();
            Engine myEngine = carFactory.CreateEngine();

            myEngine.GetPower();

            carFactory = new FordFactory();
            myCar      = carFactory.CreateCar();
            myCar.Info();
            myEngine = carFactory.CreateEngine();
            myEngine.GetPower();

            carFactory = new MercedesFactory();
            myCar      = carFactory.CreateCar();
            myCar.Info();
            myEngine = carFactory.CreateEngine();
            myEngine.GetPower();

            Console.ReadKey();
        }