コード例 #1
0
 static void Main(string[] args)
 {
     ShapeFactory.GetShape(Const.ShapeType.Circle).Draw();
     ShapeFactory.GetShape(Const.ShapeType.Rectangle).Draw();
     ShapeFactory.GetShape(Const.ShapeType.Square).Draw();
     ShapeFactory.GetShape(Const.ShapeType.Triangle).Draw();
     Console.ReadKey();
 }
コード例 #2
0
        static void Main(string[] args)
        {
            ShapeFactory shapeFactory = new ShapeFactory();

            IShape shape1 = shapeFactory.GetShape("CIRCLE");

            shape1.Draw();

            IShape shape2 = shapeFactory.GetShape("RECTANGLE");

            shape2.Draw();

            IShape shape3 = shapeFactory.GetShape("SQUARE");

            shape3.Draw();

            Console.ReadLine();
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        public static void Main(String[] args)
        {
            ShapeFactory shapeFactory = new ShapeFactory();     //使用该工厂,通过传递类型信息来获取实体类的对象。

            IShape shape1 = shapeFactory.GetShape("CIRCLE");    //获取 Circle 的对象,并调用它的 draw 方法

            shape1.Draw();                                      //调用 Circle 的 draw 方法

            IShape shape2 = shapeFactory.GetShape("RECTANGLE"); //获取 Rectangle 的对象,并调用它的 draw 方法

            shape2.Draw();                                      //调用 Rectangle 的 draw 方法

            IShape shape3 = shapeFactory.GetShape("SQUARE");    //获取 Square 的对象,并调用它的 draw 方法

            shape3.Draw();                                      //调用 Square 的 draw 方法

            Console.ReadLine();
        }
コード例 #4
0
        static void Main(string[] args)
        {
            Shape shape1 = ShapeFactory.GetShape(ShapeType.Circle);

            shape1.Draw();
            Shape shape2 = ShapeFactory.GetShape(ShapeType.Square);

            shape2.Draw();

            Console.ReadKey(true);
        }
コード例 #5
0
        /// <summary>
        /// The main.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        public static void Main(string[] args)
        {
            var shapeFactory = new ShapeFactory();

            // get an object of rectangle and call its draw method
            var rectangleShape = shapeFactory.GetShape("RECTANGLE");

            rectangleShape.Draw();

            // get an object of square and call its draw method
            var squareShape = shapeFactory.GetShape("SQUARE");

            squareShape.Draw();

            // get an object of circle and call its draw method
            var circleShape = shapeFactory.GetShape("CIRCLE");

            circleShape.Draw();

            Console.ReadKey();
        }
コード例 #6
0
        static void Main(string[] args)
        {
            IShape shapeCircle = ShapeFactory.GetShape(ShapeTypes.Circle);

            shapeCircle.Draw();
            IShape shapeRectangle = ShapeFactory.GetShape(ShapeTypes.Rectangle);

            shapeRectangle.Draw();

            Console.WriteLine("Hello World!");
            Console.ReadKey();
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: achrefrejeb/DesignPatterns
        static void Main(string[] args)
        {
            List <IShape> shapes = new List <IShape>();

            shapes.Add(ShapeFactory.GetShape("Circle"));
            shapes.Add(ShapeFactory.GetShape("Square"));
            foreach (var shape in shapes)
            {
                shape.Draw();
            }

            Console.ReadLine();
        }
コード例 #8
0
        static void Main(string[] args)
        {
            var shapeFactory = new ShapeFactory();
            //获取 Circle 的对象,并调用它的 draw 方法
            var shape1 = shapeFactory.GetShape("CIRCLE");

            //调用 Circle 的 draw 方法
            shape1.Draw();

            //获取 Rectangle 的对象,并调用它的 draw 方法
            var shape2 = shapeFactory.GetShape("RECTANGLE");

            //调用 Rectangle 的 draw 方法
            shape2.Draw();

            //获取 Square 的对象,并调用它的 draw 方法
            var shape3 = shapeFactory.GetShape("SQUARE");

            //调用 Square 的 draw 方法
            shape3.Draw();

            Console.ReadKey();
        }
コード例 #9
0
        private static void Main(string[] args)
        {
            var shape = ShapeFactory.GetShape("circle");

            shape.Area();

            shape = ShapeFactory.GetShape("rectangle");
            shape.Area();

            shape = ShapeFactory.GetShape("square");
            shape.Area();

            Console.ReadKey();
        }
コード例 #10
0
        static void Main(string[] args)
        {
            ShapeFactory shapeFactory = new ShapeFactory();

            IShape shape1 = shapeFactory.GetShape("Square");

            shape1.Draw();

            IShape shape2 = shapeFactory.GetShape("Rectangle");

            shape2.Draw();

            try
            {
                IShape shape3 = shapeFactory.GetShape("Circle");
                shape3.Draw();
            }
            catch (NullReferenceException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("Exception received.");
            }
        }
コード例 #11
0
        static void Main(string[] args)
        {
            ShapeFactory factory = new ShapeFactory();

            Shape[] shape     = new Shape[10];
            Random  random    = new Random();
            double  TotalArea = 0;

            for (int i = 0; i < 10; i++)
            {
                shape[i] = factory.GetShape(random.Next(0, 3).ToString());
                shape[i].Draw();
                shape[i].Display();
                shape[i].IsLegitimate();
                Console.WriteLine("面积为{0:0.0}", shape[i].GetArea());
                Console.WriteLine("");
                TotalArea += shape[i].GetArea();
            }
            Console.WriteLine("创建的图形的总面积为: {0:0.00}", TotalArea);

            Console.ReadKey();
        }