Ejemplo n.º 1
0
        private void AddObjectToStorage(FlyweightFactory factory, SomeObject someObject)
        {
            Console.WriteLine("\nNew object adding to virtual storage.");

            var newObject = new SomeObject {
                Id = someObject.Id, Name = someObject.Name, Body = someObject.Body
            };
            var flyweight = factory.GetFlyweight(newObject);

            flyweight.Operation(someObject);
        }
Ejemplo n.º 2
0
        public void Start()
        {
            var object1 = new SomeObject {
                Id = 1, Name = "Name1", Body = "Body1"
            };
            var object2 = new SomeObject {
                Id = 2, Name = "Name2", Body = "Body2"
            };
            var object3 = new SomeObject {
                Id = 3, Name = "Name3", Body = "Body3"
            };

            var factory = new FlyweightFactory(object1, object2, object3);

            factory.ListFlyweights();

            var object4 = new SomeObject {
                Id = 4, Name = "Name4", Body = "Body4"
            };
            var object5 = new SomeObject {
                Id = 5, Name = "Name5", Body = "Body5"
            };

            AddObjectToStorage(factory, object4);
            AddObjectToStorage(factory, object5);

            var object6 = new SomeObject {
                Id = 6, Name = "Name5", Body = "Body5"
            };

            AddObjectToStorage(factory, object6);

            Console.WriteLine();

            factory.ListFlyweights();
        }