Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter car(Audi or Mercedes): ");
            string  car     = Console.ReadLine();
            Factory factory = FactoryProducer.getFactory(car);
            ITire   tire    = factory.makeTire();

            tire.tire();
            IHeadlight headlight = factory.makeHeadlight();

            headlight.headlight();
            Console.ReadLine();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            FactoryProducer factoryProducer = new FactoryProducer();
            AbstractFactory roundFactory    = factoryProducer.getFactory(true);

            roundFactory.getShape("square").draw();
            roundFactory.getShape("rectangle").draw();

            AbstractFactory shapeFactory = factoryProducer.getFactory(false);

            shapeFactory.getShape("square").draw();
            shapeFactory.getShape("rectangle").draw();

            Console.ReadKey();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            // get nano car
            AbstractFactory carFactory = FactoryProducer.GetFactory("car");
            ICar            nanoCar    = carFactory.GetCar("nano");

            nanoCar.GetSpecifications();

            // get white color
            AbstractFactory colorFactory = FactoryProducer.GetFactory("color");
            IColor          color        = colorFactory.GetColor("white");

            color.GetColor();

            Console.Read();
        }
Ejemplo n.º 4
0
        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.ReadKey();
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            //get shape factory
            AbstractFactory shapeFactory = FactoryProducer.getFactory("SHAPE");

            //get an object of Shape Circle
            Shape shape1 = shapeFactory.getShape("CIRCLE");

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

            //get an object of Shape Rectangle
            Shape shape2 = shapeFactory.getShape("RECTANGLE");

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

            //get an object of Shape Square
            Shape shape3 = shapeFactory.getShape("SQUARE");

            //call draw method of Shape Square
            shape3.draw();

            //get color factory
            AbstractFactory colorFactory = FactoryProducer.getFactory("COLOR");

            //get an object of Color Red
            Color color1 = colorFactory.getColor("RED");

            //call fill method of Red
            color1.fill();

            //get an object of Color Green
            Color color2 = colorFactory.getColor("Green");

            //call fill method of Green
            color2.fill();

            //get an object of Color Blue
            Color color3 = colorFactory.getColor("BLUE");

            //call fill method of Color Blue
            color3.fill();

            Console.ReadLine();
        }
Ejemplo n.º 6
0
        /*
         * Este padrão permite a criação de famílias de objetos
         * relacionados ou dependentes por meio de uma única
         * interface e sem que a classe concreta seja especificada
         * É o mais apropriado quando o número e os tipos gerais de
         * objetos de produtos permanecem constantes, e há diferenças
         * em produtos específicos famílias
         *
         * Quando usar:
         *  - o sistema deve ser independente de qual produto será criado e representado
         *  - o sistema deve ser configurado com uma familia de produto multiplo
         *  - uma família de objetos de produtos relacionados é projetada para ser
         *      usada em conjunto e você precisa impor essa restrição
         *  - voce quer prover uma library de produtos e voce quer revelar apenas suas interfaces
         *
         */
        static void Main(string[] args)
        {
            AbstractFactory shapef = FactoryProducer.GetFactory("shape");

            Shapes.IShape circle = shapef.GetShape("circle");
            circle.Draw();

            Shapes.IShape rectangle = shapef.GetShape("rectangle");
            rectangle.Draw();

            AbstractFactory colorf = FactoryProducer.GetFactory("color");

            Colors.IColor blue = colorf.GetColor("blue");
            blue.Fill();


            Console.ReadKey();
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            Abstract_Factory.AbstractFactory shapeFactory = FactoryProducer.GetFactory(false);
            IShape shape1 = shapeFactory.GetShape("square");

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

            shape2.DrawShape();

            Abstract_Factory.AbstractFactory roundedShapeFactory = FactoryProducer.GetFactory(true);
            IShape shape3 = roundedShapeFactory.GetShape("square");

            shape3.DrawShape();
            IShape shape4 = roundedShapeFactory.GetShape("rectangle");

            shape4.DrawShape();
        }
Ejemplo n.º 8
0
        private static void Main(string[] args)
        {
            // 初始化创建汽车的两个工厂
            Factory hongQiCarFactory = FactoryProducer.GetFactory("HongQiCarFactory");
            Factory aoDiCarFactory   = FactoryProducer.GetFactory("AoDiCarFactory");

            // 生产一辆红旗汽车
            Car hongQi = hongQiCarFactory.CreateCar();

            hongQi.Go();

            //生产一辆奥迪汽车
            Car aoDi = aoDiCarFactory.CreateCar();

            aoDi.Go();

            Console.Read();
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            //Audi
            Factory    factory        = FactoryProducer.getFactory(true); //false for Audi
            ITire      TireOfCar      = factory.makeTire();
            IHeadlight HeadlightOfCar = factory.makeHeadlight();

            TireOfCar.tire();
            HeadlightOfCar.headlight();

            //Mercedes
            factory        = FactoryProducer.getFactory(true); //true for Mercedes
            TireOfCar      = factory.makeTire();
            HeadlightOfCar = factory.makeHeadlight();
            TireOfCar.tire();
            HeadlightOfCar.headlight();

            Console.ReadLine();
        }
Ejemplo n.º 10
0
        public static void Demo()
        {
            AbstractFactory shapeGen = FactoryProducer.Generator("Shape");

            Factory.IShape c = shapeGen.ShapeCreate("Circle");
            c.Draw();
            Factory.IShape s = shapeGen.ShapeCreate("Square");
            s.Draw();

            AbstractFactory colorGen = FactoryProducer.Generator("Color");
            IColor          r        = colorGen.ColorCreate("Red");

            r.Fill();
            IColor b = colorGen.ColorCreate("Blue");

            b.Fill();

            Console.ReadLine();
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            FactoryProducer Fproducer    = new FactoryProducer();
            AbstractFactory shapeFactory = Fproducer.GetFactory("Shape");
            IShape          Circle       = shapeFactory.GetShape(shape.Circle);

            Circle.Draw(10);
            IShape Square = shapeFactory.GetShape(shape.Square);

            Square.Draw(20);

            IColor temp = shapeFactory.GetColor("");

            AbstractFactory colorFactory = Fproducer.GetFactory("Color");
            IColor          Red          = colorFactory.GetColor("Red");
            IColor          Blue         = colorFactory.GetColor("Blue");

            Red.Fill("");
            Blue.Fill("");
            Console.ReadKey();
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            PeopleFactory studentFactory = FactoryProducer.getFactory("STUDENT");

            Student student1 = studentFactory.getStudent("CNPM");

            student1.Info();

            Student student2 = studentFactory.getStudent("HTTT");

            student2.Info();

            PeopleFactory employeeFactory = FactoryProducer.getFactory("EMPLOYEE");

            Employee employee1 = employeeFactory.getEmployee("DuLich");

            employee1.Work();

            Employee employee2 = employeeFactory.getEmployee("BaoChi");

            employee2.Work();

            Console.ReadKey();
        }