Пример #1
0
        static void Main(string[] args)
        {
            AbstractFactory shapeFactory = FactoryProducer.GetFactory("shape");
            IShape          shapeCirle   = shapeFactory.GetShape("circle");

            shapeCirle.Draw();
            IShape shapeRectangle = shapeFactory.GetShape("rectangle");

            shapeRectangle.Draw();
            IShape shapeSquare = shapeFactory.GetShape("square");

            shapeSquare.Draw();

            AbstractFactory colorFactory = FactoryProducer.GetFactory("color");
            IColor          colorRed     = colorFactory.GetColor("red");

            colorRed.Fill();
            IColor colorGreen = colorFactory.GetColor("green");

            colorGreen.Fill();
            IColor colorBlue = colorFactory.GetColor("blue");

            colorBlue.Fill();

            Console.Read();
        }
Пример #2
0
        static void Main(string[] args)
        {
            AbstractFactory shapeFactory = ProducterFactory.GetFactory("Shape");

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

            shape1.Draw();

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

            shape2.Draw();

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

            shape3.Draw();

            AbstractFactory colorFactory = ProducterFactory.GetFactory("Color");

            IColor color1 = colorFactory.GetColor("Color1");

            color1.Fill();

            IColor color2 = colorFactory.GetColor("Color2");

            color2.Fill();

            IColor color3 = colorFactory.GetColor("Color3");

            color3.Fill();

            Console.ReadKey();
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        public static void Main(String[] args)
        {
            //获取形状工厂
            AbstractFactory shapeFactory = FactoryProducer.GetFactory("SHAPE");

            //获取形状为 Circle 的对象
            IShape shape1 = shapeFactory.GetShape("CIRCLE");

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

            //获取形状为 Rectangle 的对象
            IShape shape2 = shapeFactory.GetShape("RECTANGLE");

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

            //获取形状为 Square 的对象
            IShape shape3 = shapeFactory.GetShape("SQUARE");

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

            //获取颜色工厂
            AbstractFactory colorFactory = FactoryProducer.GetFactory("COLOR");

            //获取颜色为 Red 的对象
            IColor color1 = colorFactory.GetColor("RED");

            //调用 Red 的 fill 方法
            color1.Fill();

            //获取颜色为 Green 的对象
            IColor color2 = colorFactory.GetColor("Green");

            //调用 Green 的 fill 方法
            color2.Fill();

            //获取颜色为 Blue 的对象
            IColor color3 = colorFactory.GetColor("BLUE");

            //调用 Blue 的 fill 方法
            color3.Fill();

            Console.ReadLine();
        }
Пример #4
0
        static void Main(string[] args)
        {
            AbstractFactory shapeFactory = FactoryProducer.GetFactory(false);
            IShape          shape1       = shapeFactory.GetShape("Square");

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

            shape2.Draw();

            AbstractFactory roundShapeFactory = FactoryProducer.GetFactory(true);
            IShape          shape3            = roundShapeFactory.GetShape("Square");

            shape3.Draw();
            IShape shape4 = roundShapeFactory.GetShape("Rectangle");

            shape4.Draw();
        }