Пример #1
0
        static void Main()
        {
            Shape shape;

            //圆形
            Console.WriteLine("创建半径为5的圆形");
            shape = ShapeFactory.GetShape("circle", 5);
            shape.ShowArea();
            //矩形
            Console.WriteLine("创建边长为2, 4的矩形");
            shape = ShapeFactory.GetShape("rect", 2, 4);
            shape.ShowArea();
            //三角形
            Console.WriteLine("创建底3, 高4的三角形");
            shape = ShapeFactory.GetShape("triangle", 3, 4);
            shape.ShowArea();
            //正方形
            Console.WriteLine("创建边长为1的正方形");
            shape = ShapeFactory.GetShape("square", 1);
            shape.ShowArea();
            Console.ReadKey();
        }
Пример #2
0
        static void Main(string[] args)
        {
            Shape shape_1;

            shape_1 = ShapeFactory.GetShape("TRIANGLE");
            shape_1.Draw();
            Console.WriteLine("The area is : " + shape_1.Area);
            Shape shape_2;

            shape_2 = ShapeFactory.GetShape("CIRCLE");
            shape_2.Draw();
            Console.WriteLine("The area is : " + shape_2.Area);
            Shape shape_3;

            shape_3 = ShapeFactory.GetShape("SQUARE");
            shape_3.Draw();
            Console.WriteLine("The area is : " + shape_3.Area);
            Shape shape_4;

            shape_4 = ShapeFactory.GetShape("RECTANGLE");
            shape_4.Draw();
            Console.WriteLine("The area is : " + shape_4.Area);
        }