Example #1
0
        //Use sharing to support large numbers of fine-grained objects efficiently.
        static void Main(string[] _)
        {
            var factory = new ShapeFactory();
            var shape   = factory.GetShape(nameof(Circle));

            shape.GetShapeName();

            shape = factory.GetShape(nameof(Circle));
            shape.GetShapeName();

            shape = factory.GetShape(nameof(Rectangle));
            shape.GetShapeName();

            shape = factory.GetShape(nameof(Rectangle));
            shape.GetShapeName();


            Console.WriteLine($"count: {factory.ShapeCount}");
            Console.ReadKey();
        }
Example #2
0
        static void Main(string[] args)
        {
            ShapeFactory.GetShape(ShapeType.Circle).Draw(5, 10);
            ShapeFactory.GetShape(ShapeType.Circle).Draw(10, 5);
            ShapeFactory.GetShape(ShapeType.Square).Draw(15, 1);
            ShapeFactory.GetShape(ShapeType.Square).Draw(1, 15);
            ShapeFactory.GetShape(ShapeType.Point).Draw(4, 6);
            ShapeFactory.GetShape(ShapeType.Point).Draw(6, 4);

            Console.ReadLine();
        }
Example #3
0
        static void Main(string[] args)
        {
            //Flyweight Factory
            ShapeFactory shapeFactory = new ShapeFactory();

            IShape shapeOne = shapeFactory.GetShape("Triangle");

            shapeOne.draw();

            IShape shapeTwo = shapeFactory.GetShape("Triangle");

            shapeTwo.draw();

            IShape shapeThree = shapeFactory.GetShape("Triangle");

            shapeThree.draw();

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

            shapeFour.draw();

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

            shapeFive.draw();

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

            shapeSix.draw();

            Console.WriteLine($"Total Shape Objects {shapeFactory.ShapesCount}");
            Console.Read();
        }
        static void Main(string[] args)
        {
            ShapeFactory sf = new ShapeFactory();
            IShape       s  = sf.GetShape("Rectangle");

            s.Print();

            s = sf.GetShape("Circle");
            s.Print();

            s = sf.GetShape("Circle");
            s.Print();

            s = sf.GetShape("Rectangle");
            s.Print();

            s = sf.GetShape("Circle");
            s.Print();

            Console.WriteLine("Total Objects created : " + sf.TotalObjectsCreated);
            Console.ReadLine();
        }
Example #5
0
        static void Main(string[] args)
        {
            var factory = new ShapeFactory();

            var shape = factory.GetShape(nameof(Circle));

            shape.GetShapeName();

            shape = factory.GetShape(nameof(Circle));

            shape.GetShapeName();

            shape = factory.GetShape(nameof(Regtangle));

            shape.GetShapeName();

            shape = factory.GetShape(nameof(Regtangle));

            shape.GetShapeName();

            Console.WriteLine($"The total object count: {factory.ShapesCount}");

            Console.ReadKey();
        }
Example #6
0
 public static void Run()
 {
     Console.WriteLine("\n Red color Circles ");
     for (int i = 0; i < 3; i++)
     {
         Circle circle = (Circle)ShapeFactory.GetShape("circle");
         circle.SetColor("Red");
         circle.Draw();
     }
     Console.WriteLine("\n Green color Circles ");
     for (int i = 0; i < 3; i++)
     {
         Circle circle = (Circle)ShapeFactory.GetShape("circle");
         circle.SetColor("Green");
         circle.Draw();
     }
     Console.WriteLine("\n Blue color Circles");
     for (int i = 0; i < 3; ++i)
     {
         Circle circle = (Circle)ShapeFactory.GetShape("circle");
         circle.SetColor("Green");
         circle.Draw();
     }
     Console.WriteLine("\n Orange color Circles");
     for (int i = 0; i < 3; ++i)
     {
         Circle circle = (Circle)ShapeFactory.GetShape("circle");
         circle.SetColor("Orange");
         circle.Draw();
     }
     Console.WriteLine("\n Black color Circles");
     for (int i = 0; i < 3; ++i)
     {
         Circle circle = (Circle)ShapeFactory.GetShape("circle");
         circle.SetColor("Black");
         circle.Draw();
     }
     Console.ReadKey();
 }
Example #7
0
        static void Main(string[] args)
        {
            ShapeFactory  factory = new ShapeFactory();
            List <IShape> shapes  = new List <IShape>();
            int           x       = 0;
            int           y       = 0;

            shapes.Add(factory.GetShape("квадрат"));
            shapes.Add(factory.GetShape("круг"));
            shapes.Add(factory.GetShape("круг"));
            shapes.Add(factory.GetShape("точка"));
            shapes.Add(factory.GetShape("квадрат"));
            shapes.Add(factory.GetShape("круг"));
            shapes.Add(factory.GetShape("точка"));

            Random random = new Random();

            foreach (var shape in shapes)
            {
                x = random.Next(100);
                y = random.Next(100);
                shape.Draw(x, y);
            }
        }