public IComputerFactory Create(Employee e) { IComputerFactory returnValue = null; if (e.EmployeeTypeID == 1) { if (e.JobDescription == "Manager") { returnValue = new MACLaptopFactory(); } else { returnValue = new MACFactory(); } } else if (e.EmployeeTypeID == 2) { if (e.JobDescription == "Manager") { returnValue = new DellLaptopFactory(); } else { returnValue = new DellFactory(); } } return(returnValue); }
public static void Main(string[] args) { DellFactory df = new DellFactory(); AbstractClientEndPoint emp = new AbstractClientEndPoint(df); Console.WriteLine("{0}", emp.GetDeviceEmployee(new EmployeeModel { Type = EmployeeType.Contract, Name = "Seshu", Position = EmployeePositionType.TeamManager }).DeviceName); Console.ReadKey(); }
static void Main(string[] args) { Console.WriteLine("Hello Design Patterns!"); Console.WriteLine(); // Create and run the DELL factory IComputerFactory dell = new DellFactory(); Console.WriteLine(); // I need a dell desktop computer var newDellDesktopOfMine = dell.CreateDesktop("my new"); newDellDesktopOfMine.GetType(); // My brother need a dell notebook var newMacbookOfMyBrother = dell.CreateNotebook("my brother`s new"); newMacbookOfMyBrother.GetType(); Console.WriteLine(); // Create and run Apple factory IComputerFactory apple = new AppleFactory(); Console.WriteLine(); // My new MacBook Pro var newMacbookOfMine = apple.CreateNotebook("my new"); newMacbookOfMine.GetType(); // My brother`s new Mac Mini desktop computer var newMacMiniOfMyBrother = apple.CreateDesktop("my brother`s new"); newMacbookOfMyBrother.GetType(); Console.ReadLine(); }
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() { 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!"); } } }
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"); } } }