Exemple #1
0
        static void Main(string[] args)
        {
            // canonical example
            int extrinsicState = 20;

            var factory = new FlyweightFactory();

            var fa = factory.GetFlyWeight("A");

            fa.Operation(extrinsicState--);

            var fb = factory.GetFlyWeight("B");

            fb.Operation(extrinsicState--);

            var unsh = new UnsharedConcreteFlyweight();

            unsh.Operation(extrinsicState--);

            Console.WriteLine();

            // live example
            var fact = new CharacterFactory();
            var cha  = fact.GetCharacter('a');

            cha.Display(100);
        }
Exemple #2
0
        /// <summary>
        /// The test second.
        /// </summary>
        private static void TestSecond()
        {
            // Arbitrary extrinsic state
            int extrinsicstate = 22;
            FlyweightFactory flyweightFactory = new FlyweightFactory();

            // Work with different flyweight instances
            AbstractFlyweight fx = flyweightFactory.GetFlyweight("X");

            fx.Operation(--extrinsicstate);
            AbstractFlyweight fy = flyweightFactory.GetFlyweight("Y");

            fy.Operation(--extrinsicstate);
            AbstractFlyweight fz = flyweightFactory.GetFlyweight("Z");

            fz.Operation(--extrinsicstate);
            UnsharedConcreteFlyweight fu = new UnsharedConcreteFlyweight();

            fu.Operation(--extrinsicstate);

            // Wait for user
            Console.ReadKey();
        }
        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);

            UnsharedConcreteFlyweight fu = new UnsharedConcreteFlyweight();

            fu.Operation(--extrinsicstate);

            Console.ReadKey();
        }