예제 #1
0
        public static void FactoryDesign()
        {
            var           factory   = new ShapeFactory(); //creation of a shapeFactory
            IShape        aSquare   = factory.GetShape("Square");
            IShape        aCircle   = factory.GetShape("Circle");
            IShape        aTriangle = factory.GetShape("Triangle");
            List <IShape> shapeList = new List <IShape>();

            shapeList.Add(aSquare);
            shapeList.Add(aCircle);
            shapeList.Add(aTriangle);

            foreach (var shape in shapeList)
            {
                shape.Draw();
            }

            Console.ReadKey();
        }
예제 #2
0
        public FactoryPattern() : base("Factory")
        {
            var shapeFactory = new ShapeFactory();

            var circle = shapeFactory.getShape("CIRCLE");

            circle.draw();
            circle.area(7);

            var rectangle = shapeFactory.getShape("RECTANGLE");

            rectangle.draw();
            rectangle.area(2, 3);

            var square = shapeFactory.getShape("SQUARE");

            square.draw();
            square.area(5);
        }