Example #1
0
 protected virtual void Notify(SubjectEventArgs e)
 {
     foreach (IObserver obs in containers)
     {
         obs.Update(e);
     }
 }
Example #2
0
 public void BoilWater()
 {
     for (int i = 1; i < 101; i++)
     {
         if (i > 97)
         {
             SubjectEventArgs e = new SubjectEventArgs(i, "Shanghai");
             OnBoild(e);
         }
     }
 }
Example #3
0
        public void Update(SubjectEventArgs e)
        {
            if (!isDisplayed)
            {
                Console.WriteLine("Area is {0}", e.Area);
                isDisplayed = true;
            }

            if (e.Temperature < 100)
            {
                Console.WriteLine("Alarm: 当前水温{0},快开了", e.Temperature);
            }
            else
            {
                Console.WriteLine("Alarm: 当前水温{0},水开了", e.Temperature);
            }
        }
Example #4
0
 protected virtual void OnBoild(SubjectEventArgs e)
 {
     Notify(e);
 }