Beispiel #1
0
        void test()
        {
            var circleKey = Guid.NewGuid().ToString();
            var circle    = FlyweightFactory.getCircle(circleKey);

            circle.draw();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            //创建工厂类
            FlyweightFactory factory = new FlyweightFactory();

            factory.GetFlyweight("woc");
            factory.GetFlyweight("尼玛");
            factory.GetFlyweight("woc");
            Console.WriteLine(factory.Count());

            factory.Play();

            Console.ReadKey();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            FlyweightFactory factory = new FlyweightFactory();
            Flyweight        f01     = factory.getFlyweight("a");
            Flyweight        f02     = factory.getFlyweight("a");
            Flyweight        f03     = factory.getFlyweight("a");
            Flyweight        f11     = factory.getFlyweight("b");
            Flyweight        f12     = factory.getFlyweight("b");

            f01.operation(new UnsharedConcreteFlyweight("第1次调用a。"));
            f02.operation(new UnsharedConcreteFlyweight("第2次调用a。"));
            f03.operation(new UnsharedConcreteFlyweight("第3次调用a。"));
            f11.operation(new UnsharedConcreteFlyweight("第1次调用b。"));
            f12.operation(new UnsharedConcreteFlyweight("第2次调用b。"));

            Console.Read();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            int exten = 20;
            FlyweightFactory ff = new FlyweightFactory();
            Flyweight f1 = ff.GetFlyweight("X");
            f1.Operation(--exten);

            Flyweight f2 = ff.GetFlyweight("Y");
            f2.Operation(--exten);

            Flyweight f3 = ff.GetFlyweight("X");
            f3.Operation(--exten);

            string A = "大话设计模式";
            string B = "大话设计模式";
            Console.WriteLine(object.ReferenceEquals(A, B));
        }
        static void Main(string[] args)
        {
            // 定义外部状态,例如字母的位置等信息
            int externalstate = 10;
            // 初始化享元工厂
            FlyweightFactory factory = new FlyweightFactory();

            // 判断是否已经创建了字母A,如果已经创建就直接使用创建的对象A
            Flyweight fa = factory.GetFlyweight("A");

            if (fa != null)
            {
                // 把外部状态作为享元对象的方法调用参数
                fa.Operation(--externalstate);
            }
            // 判断是否已经创建了字母B
            Flyweight fb = factory.GetFlyweight("B");

            if (fb != null)
            {
                fb.Operation(--externalstate);
            }
            // 判断是否已经创建了字母C
            Flyweight fc = factory.GetFlyweight("C");

            if (fc != null)
            {
                fc.Operation(--externalstate);
            }
            // 判断是否已经创建了字母D
            Flyweight fd = factory.GetFlyweight("D");

            if (fd != null)
            {
                fd.Operation(--externalstate);
            }
            else
            {
                Console.WriteLine("驻留池中不存在字符串D");
                // 这时候就需要创建一个对象并放入驻留池中
                ConcreteFlyweight d = new ConcreteFlyweight("D");
                factory.flyweights.Add("D", d);
            }

            Console.Read();
        }
Beispiel #6
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 uf = new UnSharedConcreteFlyweight();

            uf.Operation(--extrinsicstate);
            Console.Read();
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            // 定义外部状态,例如字母的位置等信息
            int externalstate = 10;
            // 初始化享元工厂
            FlyweightFactory factory = new FlyweightFactory();

            // 判断是否已经创建了字母A,如果已经创建就直接使用创建的对象A
            Flyweight fa = factory.GetFlyweight("A");
            if (fa != null)
            {
                // 把外部状态作为享元对象的方法调用参数
                fa.Operation(--externalstate);
            }
            // 判断是否已经创建了字母B
            Flyweight fb = factory.GetFlyweight("B");
            if (fb != null)
            {
                fb.Operation(--externalstate);
            }
            // 判断是否已经创建了字母C
            Flyweight fc = factory.GetFlyweight("C");
            if (fc != null)
            {
                fc.Operation(--externalstate);
            }
            // 判断是否已经创建了字母D
            Flyweight fd = factory.GetFlyweight("D");
            if (fd != null)
            {
                fd.Operation(--externalstate);
            }
            else
            {
                Console.WriteLine("驻留池中不存在字符串D");
                // 这时候就需要创建一个对象并放入驻留池中
                ConcreteFlyweight d = new ConcreteFlyweight("D");
                factory.flyweights.Add("D", d);
            }

            Console.Read();
        }
Beispiel #8
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);

            UnsharedConcreteFlyweight uf = new UnsharedConcreteFlyweight();

            uf.Operation(--extrinsicstate);

            Console.Read();
        }