コード例 #1
0
 static void Main(string[] args)
 {
     for (int i = 0; i < 5; i++)
     {
         ShapeFactory shape = new ShapeFactory();
         ShapeType    s     = (ShapeType)i;
         if (shape.getShape(s) != null)
         {
             shape.getShape(s).draw();
         }
         Console.WriteLine();
     }
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: nhonduyen/designpatter
        static void Main(string[] args)
        {
            ShapeFactory factory = new ShapeFactory();
            var          square  = factory.getShape("square");

            square.draw();
            var rectangle = factory.getShape("rectangle");

            rectangle.draw();
            var circle = factory.getShape("circle");

            circle.draw();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            ShapeFactory factory = new ShapeFactory();
            Shape        cir     = factory.getShape("Circle");

            cir.Draw();
            Shape squrae = factory.getShape("Square");

            squrae.Draw();
            Shape rec = factory.getShape("Rectangle");

            rec.Draw();
            Console.ReadLine();
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: MartinALund/LearningCSharp
        static void Main(string[] args)
        {
            ShapeFactory shapeFactory = new ShapeFactory();
            IShape       shape1       = shapeFactory.getShape("CIRCLE");

            shape1.Draw();

            IShape shape2 = shapeFactory.getShape("SQUARE");

            shape2.Draw();

            IShape shape3 = shapeFactory.getShape("RECTANGLE");

            shape3.Draw();

            Console.ReadKey();
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: sinannar/DesignPatterns
        //https://www.tutorialspoint.com/design_pattern/factory_pattern.htm
        static void Main(string[] args)
        {
            ShapeFactory shapeFactory = new ShapeFactory();

            //get an object of Circle and call its draw method.
            Shape shape1 = shapeFactory.getShape("CIRCLE");

            //call draw method of Circle
            shape1.draw();

            //get an object of Rectangle and call its draw method.
            Shape shape2 = shapeFactory.getShape("RECTANGLE");

            //call draw method of Rectangle
            shape2.draw();

            //get an object of Square and call its draw method.
            Shape shape3 = shapeFactory.getShape("SQUARE");

            //call draw method of square
            shape3.draw();
        }
コード例 #6
0
        static void Main(string[] args)
        {
            ShapeFactory shapeFactory = new ShapeFactory();

            //获取 Circle 的对象,并调用它的 draw 方法
            Shape shape1 = shapeFactory.getShape("FactoryPattern.Circle");

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

            //获取 Rectangle 的对象,并调用它的 draw 方法
            Shape shape2 = shapeFactory.getShape("FactoryPattern.Rectangle");

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

            //获取 Square 的对象,并调用它的 draw 方法
            Shape shape3 = shapeFactory.getShape("FactoryPattern.Square");

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

            Console.ReadKey();
        }