The 'UnsharedConcreteFlyweight' class
Inheritance: Flyweight
示例#1
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();
        }
示例#2
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);
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            int extrinsicState  = 22;
            FlyweightFactory ff = new FlyweightFactory();

            Flyweight fw1 = ff.getFlyweight("X");

            fw1.operation(extrinsicState--);

            Flyweight fw2 = ff.getFlyweight("Y");

            fw1.operation(extrinsicState--);

            UnsharedConcreteFlyweight ucf = new UnsharedConcreteFlyweight();

            ucf.operation(extrinsicState--);
        }
示例#4
0
文件: Program.cs 项目: Alex-LG/DP
        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();
        }
示例#5
0
        // Client
        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++);
        }
示例#6
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();
        }
示例#7
0
        static void Main(string[] args)
        {
            int extrinsicstate = 22;

            FlyweightFactory f = new FlyweightFactory();

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

            fx.Operation(--extrinsicstate);

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

            fy.Operation(--extrinsicstate);

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

            fz.Operation(--extrinsicstate);

            Flyweight fu = new UnsharedConcreteFlyweight();

            fu.Operation(--extrinsicstate);

            Console.ReadKey();
        }