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];
}
}
}
//享元模式
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());