Ejemplo n.º 1
0
            public static void FlyWeight()
            {
                int exterinsicSate = 22;
                FlyWeightFactory factory = new FlyWeightFactory();
                factory.SetFlyWeight(new ConcreteFlyWeight(), "X");
                factory.SetFlyWeight(new ConcreteFlyWeight(), "Y");
                factory.SetFlyWeight(new ConcreteFlyWeight(), "Z");

                factory.GetConFlyWeight("X").Operation(--exterinsicSate);
                factory.GetConFlyWeight("Y").Operation(--exterinsicSate);
                factory.GetConFlyWeight("Z").Operation(--exterinsicSate);

                UnSharedConcreteFlyweight un = new UnSharedConcreteFlyweight();
                un.Operation(--exterinsicSate);

            }
Ejemplo n.º 2
0
        public void GetShapeTest()
        {
            var shape1 = FlyWeightFactory.GetShape("Circle", "Red");

            Assert.Equal("Red Circle", shape1.Draw());

            var shape2 = FlyWeightFactory.GetShape("Circle", "Red");

            Assert.Equal("Red Circle", shape1.Draw());

            var shape3 = FlyWeightFactory.GetShape("Circle", "Green");

            Assert.Equal("Red Circle", shape1.Draw());

            var shape4 = FlyWeightFactory.GetShape("Circle", "Green");

            Assert.Equal("Red Circle", shape1.Draw());
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            int extrinsicstate = 22;

            FlyWeightFactory flyWeightFactory = new FlyWeightFactory();

            FlyWeight flyWeightX = flyWeightFactory.GetFlyWeight("X");

            flyWeightX.Operation(--extrinsicstate);

            FlyWeight flyWeightY = flyWeightFactory.GetFlyWeight("Y");

            flyWeightY.Operation(--extrinsicstate);

            FlyWeight flyWeightZ = flyWeightFactory.GetFlyWeight("Z");

            flyWeightZ.Operation(--extrinsicstate);

            FlyWeight uf = new UnsharedConcreteFlyWeight();

            uf.Operation(--extrinsicstate);
        }