Flyweight.FlyweightFactory.GetFlyweight C# (CSharp) Method

GetFlyweight() public method

public GetFlyweight ( string key ) : Flyweight
key string
return Flyweight
        public Flyweight GetFlyweight(string key)
        {
            return ((Flyweight)flyweights[key]);
        }

Usage Example

Example #1
0
        public static void Run()
        {
            Console.WriteLine("This structural code demonstrates the Flyweight pattern in which a relatively small number of objects is shared many times by different clients.");

            int extrinsicstate = 22;

            FlyweightFactory factory1 = new FlyweightFactory();

            Flyweight fx = factory1.GetFlyweight("X");

            fx.Operation(--extrinsicstate);

            Flyweight fy = factory1.GetFlyweight("Y");

            fy.Operation(--extrinsicstate);

            Flyweight fz = factory1.GetFlyweight("Z");

            fz.Operation(--extrinsicstate);

            UnsharedConcreteFlyweight fu = new UnsharedConcreteFlyweight();

            fu.Operation(--extrinsicstate);

            /*
             *  ConcreteFlyweight: 21
             *  ConcreteFlyweight: 20
             *  ConcreteFlyweight: 19
             *  UnsharedConcreteFlyweight: 18
             */
        }
All Usage Examples Of Flyweight.FlyweightFactory::GetFlyweight