Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;

            //AbstractEngine bmwEngine = new BMWEngine("Diesel",3.0);
            //bmwEngine.GetInfo();
            //AbstractEngine audiEngine = new AudiEngine("Diesel", 2.0);
            //audiEngine.GetInfo();
            //AbstractEngine MBngine = new MercedesEngine("Diesel", 3.2);
            //MBngine.GetInfo();

            AbstractEngine.AbstractEngine   audiEngine  = new AudiEngine("Diesel", 2.0);
            AbstractBody.AudiBody           audiBody    = new AudiBody("Universal", "Red", 5);
            AbstractWheels.AbstractWheels   audiWheels  = new AudiWheels();
            AbstractFactory.AbstractFactory audiFactory = new AudiFactory();
            AbstractCar.AbstractCar         audi        = audiFactory.CreateCar(audiBody, audiEngine, audiWheels);
            audi.GetInfo();

            AbstractEngine.AbstractEngine   BMWEngine  = new BMWEngine("Diesel", 3.0);
            AbstractBody.BMWBody            BMWBody    = new BMWBody("Sedan", "Black", 5);
            AbstractWheels.AbstractWheels   BMWWheels  = new BMWWheels();
            AbstractFactory.AbstractFactory BMWFactory = new BMWFactory();
            AbstractCar.AbstractCar         BMW        = BMWFactory.CreateCar(BMWBody, BMWEngine, BMWWheels);
            BMW.GetInfo();

            Console.ReadLine();
        }
Esempio n. 2
0
        static void Main()
        {
            CarFactory audi_car = new AudiFactory();
            Client     c2       = new Client(audi_car);

            Console.WriteLine("Максимальная скорость {0} составляет {1} км/час. Тип кузова {2}", c2.ToString(), c2.RunMaxSpeed(), c2.RunBody());
        }
Esempio n. 3
0
 public static AudiFactory getAudiFactory()
 {
     if (audiFactory == null)
     {
         audiFactory = new AudiFactory();
     }
     return(audiFactory);
 }
Esempio n. 4
0
        static void Main(string[] args)
        {
            // Create factory directly - simulating user input or some program condition
            Console.WriteLine("Creating factory directly - simulating user input or some program condition.");
            Console.WriteLine();
            string carType = "bmw";
            ICarAbstractFactory carFactoryDirect = null;

            if (carType == "bmw")
            {
                carFactoryDirect = new BMWFactory();
            }
            else if (carType == "audi")
            {
                carFactoryDirect = new AudiFactory();
            }
            ICar    carDirect    = carFactoryDirect.GetSUV();
            IEngine engineDirect = carDirect.GetEngine();
            IDoors  doorsDirect  = carDirect.GetDoors();

            Console.WriteLine("SUV");
            Console.WriteLine(engineDirect.GetEngineType());
            Console.WriteLine(doorsDirect.GetDoorsType());
            Console.WriteLine(carDirect.GetModel());

            // Create factory from App Settings
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Creating factory from App Settings.");
            Console.WriteLine();
            ICarAbstractFactory carFactoryAppSet = FactoryLoader.LoadFromAppSettings();
            ICar    audiAppSet   = carFactoryDirect.GetHatchBack();
            IEngine engineAppSet = audiAppSet.GetEngine();
            IDoors  doorsAppSet  = audiAppSet.GetDoors();

            Console.WriteLine("Audi - Hatchback");
            Console.WriteLine(engineAppSet.GetEngineType());
            Console.WriteLine(doorsAppSet.GetDoorsType());

            // Creating factory from custom section in config file
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Creating factory from custom section in config file.");
            Console.WriteLine();
            ICarAbstractFactory carFactoryCustomSet = FactoryLoader.LoadFromCustomSettings();
            ICar    bmwCustSet    = carFactoryDirect.GetSedan();
            IEngine engineCustSet = bmwCustSet.GetEngine();
            IDoors  doorsCustSet  = bmwCustSet.GetDoors();

            Console.WriteLine("BMW - Sedan");
            Console.WriteLine(engineCustSet.GetEngineType());
            Console.WriteLine(doorsCustSet.GetDoorsType());
            Console.WriteLine(bmwCustSet.GetModel());

            Console.Read();
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            CarFactory ford_car = new FordFactory();
            Client     c1       = new Client(ford_car);

            Console.WriteLine("Kuzov: {0}    Max speed {1} is {2} km/hour", c1.KuzovAuto(), c1.ToString(), c1.RunMaxSpeed());

            CarFactory audi_car = new AudiFactory();
            Client     c2       = new Client(audi_car);

            Console.WriteLine("Kuzov: {0}    Max speed {1} is {2} km/hour ", c2.KuzovAuto(), c2.ToString(), c2.RunMaxSpeed());
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            CarFactory ford_car = new FordFactory();
            Client     c1       = new Client(ford_car);

            Console.WriteLine("Shape: {0}    Max speed {1} is {2} km/h", c1.ShapeAuto(), c1.ToString(), c1.RunMaxSpeed());

            CarFactory audi_car = AudiFactory.getAudiFactory();
            Client     c2       = new Client(audi_car);

            Console.WriteLine("Shape: {0}    Max speed {1} is {2} km/h ", c2.ShapeAuto(), c2.ToString(), c2.RunMaxSpeed());
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            CarFactory ford_car = new FordFactory();
            Client     c1       = new Client(ford_car);

            Console.WriteLine("Максимальная скорость {0} в типе кузова {2} составляет {1} км/час", c1.ToString(), c1.RunMaxSpeed(), c1.TypeBodywork());

            CarFactory audi_car = new AudiFactory();
            Client     c2       = new Client(audi_car);

            Console.WriteLine("Максимальная скорость {0} в типе кузова {2} составляет {1} км/час", c2.ToString(), c2.RunMaxSpeed(), c2.TypeBodywork());
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            CarFactory ford_car = new FordFactory();
            CarFactory audi_car = new AudiFactory();
            Client     c1       = new Client(ford_car);

            Client c2 = new Client(audi_car);

            Console.WriteLine("Максимальная скорость {0} составляет {1} км/час, а также кузов типа {2}",
                              c1.ToString(), c1.RunMaxSpeed(), c1.GetBodyType());

            Console.WriteLine("Максимальная скорость {0} составляет {1} км/час, а также кузов типа {2}",
                              c2.ToString(), c2.RunMaxSpeed(), c2.GetBodyType());
        }
        private void produceCar()
        {
            AbstractFactory factory;

            if (currCar is Audi)
            {
                factory = new AudiFactory(pgrs, lbls, currCar);
            }
            else if (currCar is Lamboghini)
            {
                factory = new LamboghiniFactory(pgrs, lbls, currCar);
            }
            else
            {
                return;
            }

            factory.FinishProduction += new AbstractFactory.CompletingProduction(finishProduceCar);

            Door   door;
            Wheel  wheel;
            Frame  frame;
            Seat   seat;
            Engine engine;

            if (chkDoor.Checked)
            {
                door = factory.createDoor();
            }

            if (chkWheel.Checked)
            {
                wheel = factory.createWheel();
            }

            if (chkSeat.Checked)
            {
                seat = factory.createSeat();
            }
            if (chkFrame.Checked)
            {
                frame = factory.createFrame();
            }
            if (chkEngine.Checked)
            {
                engine = factory.createEngine();
            }
        }
Esempio n. 10
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();
        }
Esempio n. 11
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());
        }
Esempio n. 12
0
        static void Main(string[] args)
        {
            var ferrariFactory  = new FerrariFactory();
            var ferrariClassic  = ferrariFactory.CreateClassicCar();
            var ferrariSporting = ferrariFactory.CreateSportingCar();

            var audiFactory  = new AudiFactory();
            var audiClassic  = audiFactory.CreateClassicCar();
            var audiSporting = audiFactory.CreateSportingCar();

            Console.WriteLine("Car type and name: {0}", ferrariClassic.ShowNameAndInfo());
            Console.WriteLine("Car type and name: {0}", ferrariSporting.ShowNameAndInfo());
            Console.WriteLine("Car type and name: {0}", audiClassic.ShowNameAndInfo());
            Console.WriteLine("Car type and name: {0}", audiSporting.ShowNameAndInfo());

            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            CarFactory ford_car = new FordFactory();
            Client     c1       = new Client(ford_car);

            Console.WriteLine("Максимальная скорость {0} составляет {1} км/час с кузовом типа \"{2}\"", c1.ToString(), c1.RunMaxSpeed(), c1.GetBodyStyle());

            CarFactory audiCar       = new AudiFactory();
            Client     clientForAudi = new Client(audiCar);

            Console.WriteLine("Максимальная скорость {0} составляет {1} км/час с кузовом типа \"{2}\"", clientForAudi.Name, clientForAudi.RunMaxSpeed(), clientForAudi.GetBodyStyle());

            var    Lada          = LadaFactory.Factory;
            Client clientForLada = new Client(Lada);

            Console.WriteLine("Максимальная скорость {0} составляет {1} км/час с кузовом типа \"{2}\"", clientForLada.Name, clientForLada.RunMaxSpeed(), clientForLada.GetBodyStyle());
        }
Esempio n. 14
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();
        }
Esempio n. 15
0
        static void Main()
        {
            var inputBrand = "Audi";

            IFactory factory;

            switch (inputBrand)
            {
            case "Audi":
                factory = new AudiFactory();
                break;

            default:
                factory = new BMWFactory();
                break;
            }

            var car        = factory.CreateCar();
            var motorCycle = factory.CreateMotorCycle();
        }
Esempio n. 16
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();
        }
Esempio n. 17
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();
        }
Esempio n. 18
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();
        }