Operation() public method

public Operation ( int extrinsicstate ) : void
extrinsicstate int
return void
Example #1
0
        static void Main(string[] args)
        {
            //externo
            int ext = 10;

            FlyweightFactory fabrica = new FlyweightFactory();

            Flyweight f1 = fabrica.getFlyweight("A");

            f1.Operation(ext++);

            Flyweight f2 = fabrica.getFlyweight("B");

            f2.Operation(ext++);
            Flyweight f3 = fabrica.getFlyweight("C");

            f3.Operation(ext++);
            Flyweight f4 = fabrica.getFlyweight("A");

            f4.Operation(ext++);

            Flyweight f5 = new UnsharedConcreteFlyweight();

            f5.Operation(ext++);

            Console.ReadLine();
        }
Example #2
0
        static void Main()
        {
            var factoryFlyweight = new FlyweightFactory();

            #region Static Flyweight

            Console.WriteLine("Создание разделяемых (статичных) объектов");

            var flyweightA = factoryFlyweight.GetFlyweight("a");
            flyweightA.Operation(500);

            var duplicateFlyweightA = factoryFlyweight.GetFlyweight("a");
            duplicateFlyweightA.Operation(1);

            int stateA = (flyweightA as ConcreteFlyweight).objectState;
            Console.WriteLine($"a: {stateA}");

            #endregion

            #region Dynamic Flyweight

            Console.WriteLine("Создание неразделяемых (динамических) экземпляров");

            var dynamicFlyweightB = new UnsharedConcreteFlyweight();
            dynamicFlyweightB.Operation(7);
            Console.WriteLine($"b: {dynamicFlyweightB.instanceState}");

            #endregion

            Console.ReadKey();
        }
Example #3
0
        static void Main(string[] args)
        {
            // Arbitrary extrinsic state

            int extrinsicstate = 22;

            FlyweightFactory factory = new FlyweightFactory();

            // Work with different flyweight instances

            Flyweight fx = factory.GetFlyweight("X");

            fx.Operation(--extrinsicstate);

            Flyweight fy = factory.GetFlyweight("Y");

            fy.Operation(--extrinsicstate);

            Flyweight fz = factory.GetFlyweight("Z");

            fz.Operation(--extrinsicstate);

            UnsharedConcreteFlyweight fu = new

                                           UnsharedConcreteFlyweight();

            fu.Operation(--extrinsicstate);

            // Wait for user

            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            try
            {
                int extrinsicstate = 22;

                FlyweightFactory factory = new FlyweightFactory();

                Flyweight fx = factory.GetFlyweight("X");
                fx.Operation(--extrinsicstate);

                Flyweight fy = factory.GetFlyweight("Y");
                fy.Operation(--extrinsicstate);

                Flyweight fz = factory.GetFlyweight("Z");
                fz.Operation(--extrinsicstate);

                UnsharedConcreteFlyweight fu = new

                                               UnsharedConcreteFlyweight();

                fu.Operation(--extrinsicstate);
            }
            finally
            {
                Console.ReadKey();
            }
        }
Example #5
0
        public static void Run()
        {
            Console.WriteLine("This structural code demonstrates the Flyweight pattern in which a relatively small number of objects is shared many times by different clients.");

            int extrinsicstate = 22;

            FlyweightFactory factory1 = new FlyweightFactory();

            Flyweight fx = factory1.GetFlyweight("X");

            fx.Operation(--extrinsicstate);

            Flyweight fy = factory1.GetFlyweight("Y");

            fy.Operation(--extrinsicstate);

            Flyweight fz = factory1.GetFlyweight("Z");

            fz.Operation(--extrinsicstate);

            UnsharedConcreteFlyweight fu = new UnsharedConcreteFlyweight();

            fu.Operation(--extrinsicstate);

            /*
             *  ConcreteFlyweight: 21
             *  ConcreteFlyweight: 20
             *  ConcreteFlyweight: 19
             *  UnsharedConcreteFlyweight: 18
             */
        }
Example #6
0
        static void Main(string[] args)
        {
            #region 结构实现
            // Arbitrary extrinsic state
            int extrinsicstate       = 22;
            FlyweightFactory factory = new FlyweightFactory();

            // Work with different flyweight instances
            Structural.Flyweight fx = factory.GetFlyweight("X");
            fx.Operation(--extrinsicstate);

            Structural.Flyweight fy = factory.GetFlyweight("Y");
            fy.Operation(--extrinsicstate);

            Structural.Flyweight fz = factory.GetFlyweight("Z");
            fz.Operation(--extrinsicstate);

            UnsharedConcreteFlyweight fu = new UnsharedConcreteFlyweight();
            fu.Operation(--extrinsicstate);
            #endregion

            Console.WriteLine("******************************");

            #region 实践应用
            #endregion

            Console.ReadKey();
        }
Example #7
0
        static void Main()
        {
            int
                extrinsicstate = 22;

            FlyweightFactory
                factory = new FlyweightFactory();

            Flyweight
                fx = factory.GetFlyweight("X");

            fx.Operation(--extrinsicstate);

            Flyweight
                fy = factory.GetFlyweight("Y");

            fy.Operation(--extrinsicstate);

            Flyweight
                fz = factory.GetFlyweight("Z");

            fz.Operation(--extrinsicstate);

            UnsharedConcreteFlyweight
                fu = new UnsharedConcreteFlyweight();

            fu.Operation(--extrinsicstate);
        }
Example #8
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        static void Main()
        {
            // Arbitrary extrinsic state
            int extrinsicstate = 22;

            FlyweightFactory factory = new FlyweightFactory();

            // Work with different flyweight instances
            Flyweight fx = factory.GetFlyweight("X");
            fx.Operation(--extrinsicstate);

            Flyweight fy = factory.GetFlyweight("Y");
            fy.Operation(--extrinsicstate);

            Flyweight fz = factory.GetFlyweight("Z");
            fz.Operation(--extrinsicstate);

            UnsharedConcreteFlyweight fu = new
              UnsharedConcreteFlyweight();

            fu.Operation(--extrinsicstate);

            // Wait for user
            Console.ReadKey();
        }
Example #9
0
        static void Main(string[] args)
        {
            int extrinsicstate = 22;

            FlyweightFactory factory = new FlyweightFactory();

            Flyweight fx = factory.GetFlyweight("X");

            fx.Operation(--extrinsicstate);

            Flyweight fy = factory.GetFlyweight("Y");

            fy.Operation(--extrinsicstate);

            Flyweight fz = factory.GetFlyweight("Z");

            fz.Operation(--extrinsicstate);

            Flyweight uf = new UnsharedConcreteFlyweight();

            uf.Operation(--extrinsicstate);

            Console.WriteLine();

            WebSiteFactory webSiteFactory = new WebSiteFactory();

            WebSite wx = webSiteFactory.GetWebSiteCategory("產品展示");

            wx.Use(new User("小菜"));

            WebSite wy = webSiteFactory.GetWebSiteCategory("產品展示");

            wy.Use(new User("大鳥"));

            WebSite wz = webSiteFactory.GetWebSiteCategory("產品展示");

            wz.Use(new User("嬌嬌"));

            WebSite wl = webSiteFactory.GetWebSiteCategory("部落格");

            wl.Use(new User("老頭"));

            WebSite wm = webSiteFactory.GetWebSiteCategory("部落格");

            wm.Use(new User("明明"));

            WebSite wn = webSiteFactory.GetWebSiteCategory("部落格");

            wn.Use(new User("寶寶"));

            Console.WriteLine($"網站分類總數為: {webSiteFactory.GetWebStieCount()}");

            Console.ReadLine();
        }
Example #10
0
        static void Main()
        {
            /*
             *  Structural Flyweight usage
             */

            int extrinsicState = 21;

            StructuralFlyweightFactory factory = new StructuralFlyweightFactory();

            // work with different flyweight instances
            Structural.Flyweight fx = factory.GetFlyweight("X");
            fx.Operation(--extrinsicState);

            Structural.Flyweight fy = factory.GetFlyweight("Y");
            fy.Operation(--extrinsicState);

            Structural.Flyweight fz = factory.GetFlyweight("Z");
            fz.Operation(--extrinsicState);

            UnsharedConcreteFlyweight fUnshared = new UnsharedConcreteFlyweight();

            fUnshared.Operation(--extrinsicState);

            /*
             *  Real-World flyweight
             */

            // Build a document with text
            string document = "AACCBBCB";

            char[] chars = document.ToCharArray();

            RealWorldFlyweightFactory characterFactory = new RealWorldFlyweightFactory();

            // extrinsic state
            int pointSize = 10;

            // for each character, use a flyweight object
            foreach (char c in chars)
            {
                pointSize++;
                Character character = characterFactory.GetCharacter(c);
                character.Display(pointSize);
            }
        }
Example #11
0
        static void Main()
        {            
            int extrinsicstate = 22;

            FlyweightFactory factory = new FlyweightFactory();
            
            Flyweight fx = factory.GetFlyweight("X");
            fx.Operation(--extrinsicstate);

            Flyweight fy = factory.GetFlyweight("Y");
            fy.Operation(--extrinsicstate);

            Flyweight fz = factory.GetFlyweight("Z");
            fz.Operation(--extrinsicstate);

            UnsharedConcreteFlyweight fu = new UnsharedConcreteFlyweight();

            fu.Operation(--extrinsicstate);
            
            Console.ReadKey();
        }
Example #12
0
        private static void Main()
        {
            var extrinsicstate = 100;

            var flyweightFactory = new FlyweightFactory();

            var flyweightX = flyweightFactory.GetFlyweight("X");

            flyweightX.Operation(--extrinsicstate);

            var flyweightY = flyweightFactory.GetFlyweight("Y");

            flyweightY.Operation(--extrinsicstate);

            var flyweightZ = flyweightFactory.GetFlyweight("Z");

            flyweightZ.Operation(--extrinsicstate);

            var unsharedConcreteFlyweight = new UnsharedConcreteFlyweight();

            unsharedConcreteFlyweight.Operation(--extrinsicstate);

            Console.ReadKey();
        }