Пример #1
0
        static void Main(string[] args)
        {
            Secretary     qt  = new Secretary();
            StockObserver ts1 = new StockObserver("one", qt);
            Observer      ts2 = new NBAObserver("two", qt);

            qt.Update += new EventHandler(ts1.Update);
            qt.Update += new EventHandler(ts2.Update);

            qt.SecretaryAction = "come back";
            //qt.Notify2();
            //qt.Attach(ts1);
            //qt.Attach(ts2);
            qt.Notify();

            Console.Read();
        }
Пример #2
0
        static void Main(string[] args)
        {
            Boss      huhansan = new Boss();
            Secretary xiaomi   = new Secretary();

            StockObserver tongshi1 = new StockObserver("必胜客", huhansan);
            NbaObserver   tongshi2 = new NbaObserver("臭弟弟", xiaomi);

            huhansan.Update += new EventHandler(tongshi1.CloseStock);
            xiaomi.Update   += new EventHandler(tongshi2.CloseNba);

            huhansan.SubjectState = "我胡汉三有回来了!";
            xiaomi.SubjectState   = "老板回来了!";


            huhansan.Notify();
            xiaomi.Notify();

            Console.Read();
        }