public static FactoryBase GetFactory(string shapeName) { FactoryBase factory; switch (shapeName) { case "Square": factory = new SquareFactory(); break; case "Triangle": factory = new TriangleFactory(); break; default: factory = null; break; } return(factory); }
static void Main(string[] args) { IPolygonFactory factory; var shape = Console.ReadLine(); switch (shape) { case "Rectangle": factory = new RectangleFactory(); break; case "Triangle": factory = new TriangleFactory(); break; default: throw new NotImplementedException(); } var button = factory.CreatePolygon(); button.DrawPolygon(); }