Using system;
Namespace Pattern
{
/// <Summary>
/// Summary description for class1.
/// </Summary>
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];
}
}
}
// Metadata Mode
Flyweightfactory factory = new flyweightfactory ();
Console. writeline (factory. getinstance ("AAA"). gethashcode (). tostring ());
Console. writeline (factory. getinstance ("BBB"). gethashcode (). tostring ());
Console. writeline (factory. getinstance ("AAA"). gethashcode (). tostring ());