Design Pattern 4-Flyweight

xiaoxiao2021-03-06  64

Using system;

namespace Pattern {///

/// Summary description for Class1 /// public interface flyweight {void act ();} public class Concerateflyweight:. flyweight {public Concerateflyweight () {} public void act ( ) {System.Console.writeline ("Concerate Flyweight");}} public class flyweightfactory {

System.Collections.Hashtable ht = new System.Collections.Hashtable (); public flyweightFactory () {} public flyweight getinstance (string key) {if (ht [key] == null) {ht.Add (key, new Concerateflyweight ( ));} Return (flyweight) HT [key];

}}} // Enjoyment Mode FlyweightFactory Factory = New FlyweightFactory (); console.writeline ("aaa"). GetHashcode (). Tostring ()); console.writeline (Factory.GetInstance ("BBB") .Gethashcode (). TOSTRING ()); console.writeline (Factory.GetInstance ("aaa"). GetHashcode (). Tostring ());

转载请注明原文地址:https://www.9cbs.com/read-113104.html

New Post(0)