static void Main(string[] args) { //После реализации шаблона «Фабрика» с помощью рефлексии осталась //одна проблема – жесткая связь между клиентским кодом и фабрикой //CarFactory carFactory = new CarFactory() CarFactory carFactory = new CarFactory(); ICar[] cars = { carFactory.CreateInstance("Bus", "275", "100", "1000"), carFactory.CreateInstance("Truck", "100", "50", "750"), carFactory.CreateInstance("Motobike", "75", "150", "1250") }; // Factory без рефлексии //ICar[] cars = { // CarFactory.GetCar("Bus", "275", "100", "1000"), // CarFactory.GetCar("Truck", "100", "50", "750"), // /*CarFactory.GetCar("Motobike", "75", "150", "1250")*/}; foreach (var item in cars) { Console.WriteLine($"Автомобиль: {item.GetType()}, {item}"); } Console.ReadLine(); }
static void Main(string[] args) { CarFactory car = new CarFactory(); ICar c = car.GetCar(CarFactory.carType.Fast); c.Run(); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine($"{GetCar()}"); Console.WriteLine($"{CarFactory.GetCarOfTheYear()}"); Console.WriteLine($"{CarFactory.GetSpecificCar("Lambo")}"); Console.WriteLine($"{CarFactory.GetSpecificCar("Vantage")}"); Console.WriteLine($"{CarFactory.GetSpecificCar("Fiat 147")}"); }
static void Main(string[] args) { var carFactory = new CarFactory(); var honda = carFactory.BuildVehicle("Honda", "Element"); var toyota = carFactory.BuildVehicle("Toyota", "Prius"); var subaru = carFactory.BuildVehicle("Subaru", "Impreza"); Console.WriteLine($"My three cars are a {honda.Make} {honda.Model}, {toyota.Make} {toyota.Model} and a {subaru.Make} {subaru.Model}"); Console.ReadKey(); }
static void Main(string[] args) { CarFactory carFactory = new CarFactory(); ICarSupplier carSuppllier = carFactory.GetCar(CarFactory.CarType.Peugeot); carSuppllier.Start(); carSuppllier = carFactory.GetCar(CarFactory.CarType.Benz); carSuppllier.Start(); carSuppllier = carFactory.GetCar(CarFactory.CarType.Bmw); carSuppllier.Start(); }
public void BeginShowCase() { ICarSupplier objCarSupplier = CarFactory.GetCarInstance((int)Carmodels.Audi); objCarSupplier.GetCarModel(); Console.WriteLine("And the color is " + objCarSupplier.CarColor); objCarSupplier = CarFactory.GetCarInstance((int)Carmodels.Bmw); objCarSupplier.GetCarModel(); Console.WriteLine("And the color is " + objCarSupplier.CarColor); Console.ReadLine(); }
static void Main(string[] args) { CarFactory[] myCars = new CarFactory[2]; myCars[0] = new BMWFactory(); myCars[1] = new ToyotaFactory(); foreach (CarFactory factory in myCars) { Car product = factory.CreateCar(); Console.WriteLine("Created {0}", product.GetType().Name); Console.ReadLine(); } }
static void Main(string[] args) { var rnd = new Random(); CarFactory factory = null; if (rnd.Next(0, 1) == 0) { factory = new BMWFactory(); } else { factory = new AUDIFactory(); } Assemble(factory.ConstructBody(), factory.ConstructEngine(), factory.ConstructInterior()); }
static void Main(string[] args) { // https://en.wikipedia.org/wiki/Factory_pattern while (true) { Console.WriteLine("What car would you like to make?"); var i = 1; foreach (var name in Enum.GetNames(typeof(ManufacturerEnum)).OrderBy(x => x)) { Console.WriteLine("{0}. {1}", i, name); i++; } var id = Console.ReadLine(); ManufacturerEnum manufacturer; switch (id) { case "1": manufacturer = ManufacturerEnum.Audi; break; case "2": manufacturer = ManufacturerEnum.BMW; break; case "3": manufacturer = ManufacturerEnum.Mercedes; break; case "4": manufacturer = ManufacturerEnum.Volkswagen; break; default: return; } var car = CarFactory.CreateCar(manufacturer); Console.WriteLine(); Console.WriteLine("{0} {1}: {2} - {3} - {4}", car.Manufacturer, car.Model, car.Door, car.Tires, car.Engine); Console.WriteLine(); } }
static void Main(string[] args) { CarFactory factory = null; // This 3 'Console.WriteLine' lines display information to the user so they know how to interact with the program. Console.WriteLine("What car type would you like to buy?"); Console.WriteLine("1. Toyota"); Console.WriteLine("2. Suzuki"); Console.WriteLine("Type 't' for 'toyota' and 's' for 'suzuki'"); Console.WriteLine("Then hit ENTER\n"); string car;// This line reads in what the user has inputed, and also declares the variable 'car' car = Console.ReadLine(); // An if statement that uses the variable 'car' to see if the user inputed either a 'toyota' or a 'suzuki'. // If the user inputed 'toyota', then the infomation from 'ToyotaFactory' will be called and displayed for the user to see. if (car == "t") { ToyotaFactory tf = new ToyotaFactory(); factory = tf; } // If the user inputed 'suzuki', then the infomation from 'SuzukiFactory' will be called and displayed for the user to see. else if (car == "s") { SuzukiFactory sf = new SuzukiFactory(); factory = sf; } else // Incase the user input a invalid response they will get a message telling them so. { Console.WriteLine("\nIncorrect answer please try again!"); } CarAssembler ca = new CarAssembler(); ca.AssembleCar(factory); Console.ReadKey(); }
public void AssembleCar(CarFactory factory) { factory.GetCar(); }