Exemple #1
0
        static void Main(string[] args)
        {
            // Arbitrary extrinsic state

            int extrinsicstate = 22;

            FlyweightFactory factory = new FlyweightFactory();

            // Work with different flyweight instances

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

            fx.Operation(--extrinsicstate);

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

            fy.Operation(--extrinsicstate);

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

            fz.Operation(--extrinsicstate);

            UnsharedConcreteFlyweight fu = new UnsharedConcreteFlyweight();

            fu.Operation(--extrinsicstate);

            // Wait for user

            Console.ReadKey();
        }
Exemple #2
0
        public void Test()
        {
            Console.WriteLine("单纯享元模式");


            // 初始化 享元工厂
            FlyweightFactory factory = new FlyweightFactory();

            // 通过享元工厂类来创建享元类
            IFlyweight fly = factory.Factory('a');

            fly.Operation("罗马字符");

            fly = factory.Factory('b');
            fly.Operation("阿拉伯字符");

            fly = factory.Factory('a');
            fly.Operation("阿拉伯字符");

            fly = factory.Factory('b');
            fly.Operation("罗马字符");
        }
Exemple #3
0
        public void Test()
        {
            Console.WriteLine("复合享元模式");


            // 初始化 享元工厂
            FlyweightFactory factory = new FlyweightFactory();

            // 通过享元工厂类来创建享元类
            IFlyweight fly = factory.Factory("abc");

            fly.Operation("罗马字符");

            fly = factory.Factory("bca");
            fly.Operation("阿拉伯字符");

            fly = factory.Factory("cba");
            fly.Operation("阿拉伯字符");

            fly = factory.Factory("abcba");
            fly.Operation("罗马字符ZZZ");
        }
Exemple #4
0
        public void Launch()
        {
            int extrinsicState = 22;

            FlyweightFactory factory = new FlyweightFactory();

            IFlyweight flyweightA = factory.GetFlyweight("Flyweight A");
            IFlyweight flyweightB = factory.GetFlyweight("Flyweight B");
            IFlyweight flyweightC = factory.GetFlyweight("Flyweight C");

            flyweightA.Operation(--extrinsicState);
            flyweightB.Operation(--extrinsicState);
            flyweightC.Operation(--extrinsicState);
        }
Exemple #5
0
        public void UsageMethod()
        {
            int extrinsicstate       = 22;
            FlyweightFactory factory = new FlyweightFactory();
            IFlyweight       fx      = factory.GetFlyweight("X");

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

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

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

            fu.Operation(--extrinsicstate);
        }
Exemple #6
0
        void Main()
        {
            int size = 22;

            FlyweightFactory factory = new FlyweightFactory();

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

            fx.Operation(--size);

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

            fy.Operation(--size);

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

            fz.Operation(--size);

            IFlyweight fu = new UnSharedConcreteFlyweight();

            fu.Operation(--size);
        }