示例#1
0
        static void RunFlyWeight()
        {
            // 享元模式更在于对象的重复利用 对象可以存储在内存中 或其他地方
            // 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);
        }
示例#2
0
        static void Main(string[] args)
        {
            int extrinsicstate       = 10;
            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);

            Console.ReadLine();
        }