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

 public class Subject {                             
   // Subject instance variables

   private ArrayList observers = new ArrayList();   

   public void Attach(Observer o){                  
     observers.Add(o);
   }

   public void Detach(Observer o){
     observers.Remove(o);
   }

   public void Notify(){                            
     foreach(Observer o in observers) o.Update();   
   }                                                

   public SubjectState GetState(){                  
     return new SubjectState();                     
   }                                                
 }

 public class SubjectState {                        
   // Selected state of the subject
 }
}
 
 
 
The subject class.
 
 
The list of observers.
 
A method that handles subscription.
 
 
 
 
 
 
 
A method that updates all
observers that subcribe to events
from this subject.
 
A method that may supply additional
information to an observer upon 
request.
 
 
A sketch of the class SubjectState.