观察者模式

interface ISubject
{
    void registerInterest(IObserver ob);
}
interface IObserver
{
    void Update();
}
public class Subject : ISubject
{
    ArrayList al = new ArrayList();

    public void registerInterest(IObserver ob)
    {
          al.Add(ob);
     }

     void sendNotify()
     {
            foreach(IObserver ob in al)
            {
                  ob.Update();
             }
      }

     void xxxxxxxxxxx()
     {
            sendNotify();
      }
}
public class AObserver
{
    public void Update()
    {

     }
}

public class BObserver
{
    public void Update()
    {

     }
}
public static void Main()
{
       .......

}

 

posted @ 2015-11-30 11:36  yasepix  阅读(112)  评论(0编辑  收藏  举报