예제 #1
0
        static void Main(string[] args)
        {
            var subject   = new Subject();
            var observerA = new Observer("Observer A");
            var observerB = new Observer("Observer B");
            var observerC = new Observer("Observer C");

            Console.WriteLine("Intially suppose Subject has already written total " + subject.Articles + " article");
            Console.WriteLine("\n*******************************************************************************\n");
            Console.WriteLine("Registering observers A and B for future articles...............");
            subject.registerObserver(observerA);
            subject.registerObserver(observerB);
            Console.WriteLine("New article published by Subject,so now observers A and B will be notified....\n");
            subject.Articles++;
            Console.WriteLine("---------------------------------------------------------------------------\n");
            Console.WriteLine("Registering observer C for future articles and unregistering observer B from the future articles...............");
            subject.registerObserver(observerC);
            subject.unregisterObserver(observerB);
            Console.WriteLine("New article published by Subject,so now observers A and C will be notified....\n");
            subject.Articles++;
            Console.WriteLine("\n*******************************************************************************\n");
            Console.WriteLine("Finally Subject has written total " + subject.Articles + " article\n");
        }
예제 #2
0
 public ForecastDisplay(Subject weatherData)
 {
     this.weatherData = weatherData;
     weatherData.registerObserver(this);
 }
 public CurrentConditionDisplay(Subject weatherData)
 {
     this.weatherData = weatherData;
     weatherData.registerObserver(this);
 }
 //register this observer in the constructor
 public CurrentConditionsDisplay(Subject weatherData)
 {
     this.weatherData = weatherData;
     //register this instance
     weatherData.registerObserver(this);
 }
예제 #5
0
 public StatisticsDisplay(Subject weatherData)
 {
     this.weatherData = weatherData;
     weatherData.registerObserver(this);
 }