public Ship CreateShip(ShipType st) { Ship ship; switch (st) { case ShipType.UFOShip: ship = new UFOShip(); break; case ShipType.RocketShip: ship = new RocketShip(); break; default: ship = new RocketShip(); break; } return(ship); }
static void Main(string[] args) { Ship ship = new UFOShip(); Console.WriteLine("What type of ship? U or R"); string res = Console.ReadLine(); // Very bad // ShipType st; if (res == "u") { st = ShipType.UFOShip; } else { st = ShipType.RocketShip; } ShipFactory sf = new ShipFactory(); ship = sf.CreateShip(st); DoStuff(ship); Console.ReadLine(); }