- public class ProxySubject : ISubject
- {
- //组合一下
- private static ISubject _Subject = new RealSubject();
- public void DoSomething()
- {
- try
- {
- Console.WriteLine("prepare DoSomething...");
- _Subject.DoSomething();
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- throw ex;
- }
- }
- private static Dictionary<string, bool> ProxyDictionary = new Dictionary<string, bool>();
- public bool GetSomething()
- {
- try
- {
- Console.WriteLine("prepare GetSomething...");
- string key = "Proxy_GetSomething";
- bool bResult = false;
- if (!ProxyDictionary.ContainsKey(key))
- {
- bResult = _Subject.GetSomething();
- ProxyDictionary.Add(key, bResult);
- }
- else
- {
- bResult = ProxyDictionary[key];
- }
- return bResult;
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- throw ex;
- }
- }
- }