コード例 #1
0
        // use to demonstrate the Factory Design Pattern
        public static void ExecuteDemo()
        {
            //get ShapeFactory object
            ShapeFactory shapeFactory = new ShapeFactory();

            //get Shape Rectangle
            Shape shape1 = shapeFactory.GetShape("rectangle");

            shape1.Draw();

            //get Shape Square
            Shape shape2 = shapeFactory.GetShape("square");

            shape2.Draw();

            //get Shape Circle
            Shape shape3 = shapeFactory.GetShape("circle");

            shape3.Draw();

            Console.ReadLine();
        }
コード例 #2
0
        public static void CallFactory()
        {
            IShape _IShape;

            Console.WriteLine("Type shape to display.");
            string sh = Console.ReadLine();

            _IShape = ShapeFactory.GetShape(sh);
            Console.WriteLine("Enter shape color");
            string color = Console.ReadLine();

            _IShape.color = color;

            _IShape.Getinputs();
            _IShape.CalculateArea();
            _IShape.CalculatePerimeter();

            Console.ReadKey();
        }