static void Main(string[] args) { Shape shape; shape = ShapeFactory.GetShape("三角形"); shape.show(); shape = ShapeFactory.GetShape("圆形"); shape.show(); shape = ShapeFactory.GetShape("正方形"); shape.show(); shape = ShapeFactory.GetShape("矩形"); shape.show(); }
static void Main(string[] args) { try { IShape triangle = ShapeFactory.GetShape("triangle", 3, 4, 5); triangle.GetArea(); } catch (Exception e) { Console.WriteLine("Unsupported graphics"); } try { IShape circle = ShapeFactory.GetShape("circle", 3); circle.GetArea(); } catch (Exception e) { Console.WriteLine("Unsupported graphics"); } try { IShape square = ShapeFactory.GetShape("square", 3); square.GetArea(); } catch (Exception e) { Console.WriteLine("Unsupported graphics"); } try { IShape rectangle = ShapeFactory.GetShape("rectangle", 3, 4); rectangle.GetArea(); } catch (Exception e) { Console.WriteLine("Unsupported graphics"); } }