title: IObserver and IObservable in C# for Observer vs Delegates, Events
body: <p>All I am trying to do is implementing the observer pattern.</p>
  
  <p>So, I came up with this solution:</p>
  
  <p>We have a  PoliceHeadQuarters whose primary job is to send notifications to all those who are subscribed to it. Consider that the DSP, Inspector and SubInspector classes are subscribed to PoliceHeadQuarters.</p>
  
  <p>Using Events and Delegates I wrote</p>
  
  <pre><code>public class HeadQuarters 
  {
      public delegate void NewDelegate(object sender, EventArgs e);
      public event EventHandler NewEvent;
      public void RaiseANotification()
      {
          var handler = this.NewEvent;
          if (handler != null)
          {
              handler(this, new EventArgs());
          }
      }
  }
  
  public class SubInspector
  {
      public void Listen(object sender, EventArgs e)
      {
          MessageBox.Show(string.Format("Event Notification received by sender = {0} with eventArguments = {1}", sender, e.ToString()));
      }
  }
  
  public class Inspector
  {
      public void Listen(object sender, EventArgs e)
      {
          MessageBox.Show(string.Format("Event Notification received by sender = {0} with eventArguments = {1}", sender, e.ToString()));
      }
  }
  </code></pre>
  
  <p>and this is how I invoked it</p>
  
  <pre><code>       var headQuarters = new HeadQuarters();
          var SubInspector = new SubInspector();
          var Inspector = new Inspector();
          headQuarters.NewEvent += Inspector.Listen;
          headQuarters.NewEvent += SubInspector.Listen;
          headQuarters.RaiseANotification();
  </code></pre>
  
  <p>so, both Inspector and SubInspector classes get notification whenever there the function RaiseANotification() is invoked.</p>
  
  <p>It seems that the DotNet Framework 4, 4.5 supports a new way called IObserver and IObservable.</p>
  
  <p>Can anyone give me a super simple example using IObservable and IObserver pattern for the above scenario? I googled only to find the available examples in the internet too bloated and difficult to understand. </p>
  
  <p>My hinch: (probably i think it's wrong)</p>
  
  <pre><code>  class DSP : IObserver //since it observes the headquarters ?
    class PoliceHeadQuarters: IObservable // since here's where we send the notifications ?
  </code></pre>
  
  <p>Thanks in advance.</p>
  
  <p>EDIT: Somebody also said that the MSDN documentation is also incorrect for IObservable @ 
  <a href="https://stackoverflow.com/questions/3186981/iobservable-vs-plain-events-or-why-should-i-use-iobservable">IObservable vs Plain Events or Why Should I use IObservable?</a>.</p>