Back to notes -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'  Slide program -- Keyboard shortcut: 't'    A templates of the Observer class.Lecture 6 - slide 17 : 20
Program 2
using System.Collections;
namespace Templates.Observer {

 public class Observer {                      

   private Subject mySubject;                 
                                              
   public Observer (Subject s){               
     mySubject = s;
   }   

   public void Update(){                      
      // ...                                  

      SubjectState state = mySubject.GetState();   
                                                   
      //   if (the state is interesting){
      //      react on state change
      //   }
   }
 }
}
 
 
 
The Observer class.
 
A reference to the corresponding 
Subject.
The constructor of Observer.
 
 
 
The Update method, activated by
the subject via Notify.
 
Sends a message back to the subject,
asking what really happend.