예제 #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();
        }
예제 #2
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();
        }
예제 #3
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);
        }
예제 #4
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();
        }
예제 #5
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();
        }
예제 #6
0
        static void Main(string[] args)
        {
            List<string> menusList = new List<string>();
            menusList.Add("-Add new car");
            menusList.Add("---Get drive");
            menusList.Add("--------Exit");

            List<string> subMenusList = new List<string>();
            subMenusList.Add("---BMW car");
            subMenusList.Add("---Zaz car");

            List<string> subSubMenusList = new List<string>();
            subSubMenusList.Add("Изменить скорость");
            subSubMenusList.Add("Изменить направление");
            subSubMenusList.Add("Переключить Фары");
            subSubMenusList.Add("Показания приборов");

            List<AbstractCar> CarsList = new List<AbstractCar>();

            bool exitCondition = true;

            ZazFactory zaz = new ZazFactory();
            BMWFactory bmw = new BMWFactory();

            CarsList.Add(zaz.CreateCar("Lanos"));
            CarsList.Add(bmw.CreateCar("-X5-"));

            do
            {
                try
                {
                    switch (MenusFunc(menusList))
                    {
                        case 1:
                            Console.WriteLine("Чей автомобиль хотите создать? (de / ua)");
                            if (MenusFunc(subMenusList) == 1)
                            {
                                Console.WriteLine("Введите модель авто:");
                                CarsList.Add(bmw.CreateCar(Console.ReadLine()));
                            }
                            else
                            {
                                Console.WriteLine("Введите модель авто:");
                                CarsList.Add(zaz.CreateCar(Console.ReadLine()));
                            }
                            break;

                        case 2:
                            Console.WriteLine("На каком авто будем кататься?");
                            AbstractCar ChosenCar = CarsList[MenusFunc(
                                CarsList.Select(x => x.model).ToList<string>()) - 1];
                            do
                            {
                                switch (MenusFunc(subSubMenusList))
                                {
                                    case 1: ChosenCar.Speed += int.Parse(Console.ReadLine());
                                        break;
                                    case 2: ChosenCar.Direction += int.Parse(Console.ReadLine());
                                        break;
                                    case 3: ChosenCar.Light = !ChosenCar.Light;
                                        break;
                                    case 4:
                                        Console.WriteLine("Скорость {0}", ChosenCar.Speed);
                                        Console.WriteLine("Направление {0}", ChosenCar.Direction);
                                        Console.WriteLine("Фары {0}", ChosenCar.Light);
                                        break;
                                    default:
                                        break;
                                }

                            } while (ChosenCar.Speed > 0);
                            break;

                        default:
                            exitCondition = !exitCondition;
                            break;
                    }
                }
                catch
                {
                    Console.WriteLine("Проверте формат вводимой строки!...");
                }
            } while (exitCondition);
        }