private static AbstractManufacturerFactory CreateManufacturer(string manufacturerName, IComputerFactory computerFactory) { AbstractManufacturerFactory manufacturer; if (manufacturerName == DELLFactory.DELLFactoryName) { manufacturer = new DELLFactory(computerFactory); } else if (manufacturerName == HPFactory.HPFactoryName) { manufacturer = new HPFactory(computerFactory); } else { manufacturer = new LenovoFactory(computerFactory); } return(manufacturer); }
public static IComputerFactory CreateFactory(string manufacturer) { IComputerFactory factory; if (manufacturer == LenovoFactory.FactoryName) { factory = new LenovoFactory(); } else if (manufacturer == HpFactory.FactoryName) { factory = new HpFactory(); } else if (manufacturer == DellFactory.FactoryName) { factory = new DellFactory(); } else { throw new ArgumentException(InvalidManufacturerMessage); } return(factory); }
public static void Main() { var manufacturer = Console.ReadLine(); if (manufacturer == "HP") { var hp = new HpFactory(); var factoryBuilder = new FactoryBuilder(hp); pc = factoryBuilder.MakePersonalComputer(); laptop = factoryBuilder.MakeLaptop(); server = factoryBuilder.MakeServer(); } else if (manufacturer == "Dell") { var dell = new DellFactory(); var factoryBuilder = new FactoryBuilder(dell); pc = factoryBuilder.MakePersonalComputer(); laptop = factoryBuilder.MakeLaptop(); server = factoryBuilder.MakeServer(); } else if (manufacturer == "Lenovo") { var lenovo = new LenovoFactory(); var factoryBuilder = new FactoryBuilder(lenovo); pc = factoryBuilder.MakePersonalComputer(); laptop = factoryBuilder.MakeLaptop(); server = factoryBuilder.MakeServer(); } else { throw new InvalidArgumentException("Invalid manufacturer!"); } while (true) { var inputLine = Console.ReadLine(); if (inputLine == null || inputLine.StartsWith("Exit")) { break; } var commandParameters = inputLine.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (commandParameters.Length != 2) { throw new ArgumentException("Invalid command, command should consist of two parameters"); } var command = commandParameters[0]; var parameter = int.Parse(commandParameters[1]); if (command == "Charge") { laptop.Execute(parameter); } else if (command == "Process") { server.Execute(parameter); } else if (command == "Play") { pc.Execute(parameter); } else { Console.WriteLine("Invalid command, there are three types of commands - Play, Charge, Process"); } } }
public static void Main() { Factory factory; IComputer pc = new Computer(); IServer server = new Server(); ILaptop laptop = new Laptop(); // Hot spot, can't remove it :) I need to read the line var manufacturer = Console.ReadLine(); if (manufacturer == "HP") { factory = new HpFactory(); CreateDevices(factory, ref pc, ref server, ref laptop); } else if (manufacturer == "Dell") { factory = new DellFactory(); CreateDevices(factory, ref pc, ref server, ref laptop); } else if (manufacturer == "Lenovo") { factory = new LenovoFactory(); CreateDevices(factory, ref pc, ref server, ref laptop); } else { throw new ArgumentException("Invalid manufacturer!"); } while (true) { var command = Console.ReadLine(); if (command != null && !command.StartsWith("Exit")) { var commandParts = command.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (commandParts.Length != 2) { throw new ArgumentException("Invalid command!"); } var commandName = commandParts[0]; var commandAtribute = int.Parse(commandParts[1]); if (commandName == "Charge") { laptop.ChargeBattery(commandAtribute); } else if (commandName == "Process") { server.Process(commandAtribute); } else if (commandName == "Play") { pc.Play(commandAtribute); } else { Console.WriteLine("Invalid command!"); } } else { break; } } }
public static void Main() { string manufacturer = Console.ReadLine(); if (manufacturer == "HP") { var manufacturerFactory = new HpFactory(); pc = manufacturerFactory.CreatePc(); server = manufacturerFactory.CreateServer(); laptop = manufacturerFactory.CreateLaptop(); } else if (manufacturer == "Dell") { var manufacturerFactory = new DellFactory(); pc = manufacturerFactory.CreatePc(); server = manufacturerFactory.CreateServer(); laptop = manufacturerFactory.CreateLaptop(); } else if (manufacturer == "Lenovo") { var manufacturerFactory = new LenovoFactory(); pc = manufacturerFactory.CreatePc(); server = manufacturerFactory.CreateServer(); laptop = manufacturerFactory.CreateLaptop(); } else { throw new InvalidArgumentException("Invalid manufacturer!"); } while (true) { var command = Console.ReadLine(); if (command == null) { return; } if (command.StartsWith("Exit")) { return; } var commandProduce = command.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (commandProduce.Length != 2) { { throw new ArgumentException("Invalid command!"); } } var comandName = commandProduce[0]; var ca = int.Parse(commandProduce[1]); if (comandName == "Charge") { laptop.ChargeBattery(ca); } else if (comandName == "Process") { server.Process(ca); } else if (comandName == "Play") { pc.Play(ca); } else { Console.WriteLine("Invalid command!"); } } }