Beispiel #1
0
        static void Main(string[] args)
        {
            Subject s = new Subject();

            new AObserver(s);
            new BObserver(s);
            new CObserver(s);

            Console.WriteLine("First state change (15)");
            s.setState(15);
            Console.WriteLine("Next change (5)");
            s.setState(5);
            Console.Read();
        }
 //Implement the Update method of the Observer interface
 public void Update(Subject subject)
 {
     Console.WriteLine("New Temperature Update from "+ this.name +
         "---Highest:" + subject.MaxTemp.ToString() + ". Lowest:" + subject.MinTemp.ToString());
 }
Beispiel #3
0
        static void Main(string[] args)
        {
            Subject subject = new Subject();
            IObserver display = new Display();
            IObserver dips1 = new DisplayNew();
            subject.RegisterObserver(dips1);
            subject.RegisterObserver(display);

            subject.SetMeasurement((float)10.2, (float)11.2, (float)13.2);

            subject.RemoveObserver(display);

            subject.SetMeasurement((float)7.2, (float)8.2, (float)9.2);
        }
Beispiel #4
0
 public AObserver(Subject s)
 {
     subject = s;
     subject.attach(this);
 }
Beispiel #5
0
 /// <summary>
 /// 修改
 /// </summary>
 /// <param name="subject"></param>
 public override void update(Subject subject)
 {
     Console.WriteLine($"Octal String {Convert.ToString(subject.getState(), 8)}");
 }