title: Facade pattern combined with observer pattern
body: <p>I got an assignment to find out exactly what the facade pattern is. I have googled and found out it is meant to shield a <em>client</em> from a very complex system by making an "interface". So I have a few questions, I have seen in multiple examples is they make an C# interface for the complex system, but I have also seen a few that used A class as the "Interface" (as seen <a href="http://dofactory.com/net/facade-design-pattern" rel="nofollow">here</a>). I can only make sense of it if it is a base class that simplifies a lot of different complex method calls to different classes as in (the bank example seen <a href="http://dofactory.com/net/facade-design-pattern" rel="nofollow">here</a>) </p>
  
  <ol>
  <li><p>So my first question is if I am correct that you would implement the "interface" as a class?</p></li>
  <li><p>My other question then is, could you use facade pattern together with the observer pattern. The facade class would observe on all subjects and then control what methods in different classes should be called, depending on the subject?</p></li>
  </ol>
  
  <hr>
  
  <p>Edit: As requsted I tried to make an example project with a facade for a observer pattern and here is the result:</p>
  
  <pre><code>public class Facade
  {
  
      private Dictionary&lt;ISubject, List&lt;IObserver&gt;&gt; Subjects { get; set; }
  
      public Facade()
      {
          Subjects = new Dictionary&lt;ISubject, List&lt;IObserver&gt;&gt;();
      }
  
      public void AddObserverToSubject(ISubject sub,IObserver obs)
      {
          if (Subjects.ContainsKey(sub))
              Subjects[sub].Add(obs);
          else
          {
              List&lt;IObserver&gt; observers = new List&lt;IObserver&gt;();
              observers.Add(obs);
              Subjects.Add(sub, observers);
          }
          obs.Subject = sub;
      }
  
      public void DeleteObserverFromSubject(IObserver obs,ISubject subject)
      {
          Subjects[subject].Remove(obs);
      }
      public void Notify(ISubject subject)
      {
          foreach (var observer in Subjects[subject])
          {
              observer.Update();
          }
  
      }
  }
  
  public interface ISubject
  {
      Facade Observers { get; set; }
      int GetState();
      void SetState(int state);
  }
  
  public interface IObserver
  {
      ISubject Subject { get; set; }
      void Update();
      string Mood { get; }
  }
  </code></pre>
  
  <p>So every observer will update their mood depending on what is going on with the subject.</p>
  
  <p>I have made two implementations of IObserver and ISubject but I will only show one of each here.</p>
  
  <pre><code>public class TeacherObserver : IObserver
  {
      public ISubject Subject { get; set; }
      private int _currentSalery = 500;
      public string Mood { get; private set; }
      public TeacherObserver()
      {
          Mood = "Happy";
      }
  
  
      public void Update()
      {
          var newSalery = Subject.GetState();
          if (_currentSalery &lt; newSalery)
          {
              Mood = "Happy";
          }
          else
          {
              Mood = "Sad";
          }
          _currentSalery = newSalery;
      }
  }
  
  public class SalerySubject :ISubject
  {
      public Facade Observers { get; set; }
      private int _salery;
      public int GetState()
      {
          return _salery;
      }
  
      public void SetState(int state)
      {
          _salery = state;
          Observers.Notify(this);
      }
  }
  </code></pre>
  
  <p>So one thing I like about this is that the subject doesn't have to know about all the observers that is bound to it(this will be handled by the facade class now). But seeing from the clients view it is pretty much the same calls he would have to make:</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          Facade.Facade observer = new Facade.Facade();
          ISubject salery = new SalerySubject();
          IObserver teacher = new TeacherObserver();
          salery.Observers = observer;
          observer.AddObserverToSubject(salery,teacher);
          Console.WriteLine("Teacher is " + teacher.Mood);
          salery.SetState(100);
          Console.WriteLine("Teacher salery just went down. The teacher is now " + teacher.Mood);
      }
  }
  </code></pre>
  
  <ol start="3">
  <li>Which  leads me to thinking that it doesn't really make sense to do it with a facade, as the whole point of the facade is to make it easier for the client right? (or hide information) or am I wrong?</li>
  </ol>