title: Object and Class Communication
body: <p>I've been looking up different ways to implement communication between objects and classes in a way that maintains a decoupled, encapsulated, object-oriented approach. What I've found tends to be focused on a specific implementation and I've never seen a comparison, nor the relative pros and cons of the methods. I'm also sure that I'm not aware of them all. In addition my particular application is heavily reliant on user input (game development) and that adds another factor to the mix.</p>
  
  <p>The basic and least appealing method to me was static classes and variables where each object and class accesses a centralized listing of variables. This obviously gets massively crowded very quickly and is far too unwieldy to be practical for anything other than minor applications in my view. I also looked into MVC and MVVC (enough to pick up only the basics) but from what I saw they wouldn't be suitable for the constant input and mechanics necessary for a game loop. Finally, my current method of choice is an event system where a static class contains functions that add delegates to a particular event and when the event is called all those functions are executed. My current implementation is basically something like this:</p>
  
  <pre><code>public static class EventManager {
  
      private static Dictionary&lt;EVNT, Delegate&gt; eventTable = new Dictionary&lt;EVNT, Delegate&gt;();
  
      public static void AddHandler(EVNT evnt, Action action)
      {
          if (!eventTable.ContainsKey(evnt)) eventTable[evnt] = action;
          else eventTable[evnt] = (Action)eventTable[evnt] + action;
      }
  
      public static void AddHandler&lt;T&gt;(EVNT evnt, Action&lt;T&gt; action)
      {
          if (!eventTable.ContainsKey(evnt)) eventTable[evnt] = action;
          else eventTable[evnt] = (Action&lt;T&gt;)eventTable[evnt] + action;
      }
      //More multi-variable overloads...
  
      public static void Broadcast(EVNT evnt)
      {
          Delegate d;
          if (eventTable.TryGetValue(evnt, out d))
          {
              Action action = d as Action;
              if (action != null) action();
          }
      }
  
      public static void Broadcast&lt;T&gt;(EVNT evnt, T param)
      {
          Delegate d;
          if (eventTable.TryGetValue(evnt, out d))
          {
              Action&lt;T&gt; action = d as Action&lt;T&gt;;
              if (action != null) action(param);
          }
      }
  
      public static void RemoveHandler(EVNT evnt, Action action)
      {
          if(eventTable[evnt] != null)
              eventTable[evnt] = (Action)eventTable[evnt] - action;
          if (eventTable[evnt] == null)
              eventTable.Remove(evnt);
      }
  
      public static void RemoveHandler&lt;T&gt;(EVNT evnt, Action&lt;T&gt; action)
      {
          if (eventTable[evnt] != null)
              eventTable[evnt] = (Action&lt;T&gt;)eventTable[evnt] - action;
          if (eventTable[evnt] == null)
              eventTable.Remove(evnt);
      }
  }
  </code></pre>
  
  <p>Are there different or better ways to accomplish this 'decoupling' of objects and classes? What other ways can I implement communication, whether or not it's inferior, and how can I best follow object-oriented practices in doing so?</p>