Пример #1
0
        static void Main(string[] args)
        {
            Secretary secretary = new Secretary();

            StockObserver zhangsan = new StockObserver("张三", secretary);
            StockObserver lisi     = new StockObserver("李四", secretary);

            secretary.Attach(zhangsan);
            secretary.Attach(lisi);

            secretary.SecretaryAction = "老板回来了";
            secretary.Update();

            Console.ReadLine();
        }
Пример #2
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();
        }
Пример #3
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();
        }
Пример #4
0
        static void Main(string[] args)
        {
            Subject boss = new Boss();

            Number one = new Number("A", boss);
            Number two = new Number("B", boss);

            boss.setBossState("I'm back");
            boss.removeNumber(one);
            boss.removeNumber(two);

            Secretary lady = new Secretary();

            lady.resignNumber(one);
            lady.resignNumber(two);
            lady.setBossState("Boss is gone!");

            boss.setBossState("I'm back again!");

            Console.Read();
        }
Пример #5
0
        static void Main(string[] args)
        {
            Subject boss = new Boss();

            Number1 one = new Number1(boss);
            Number2 two = new Number2(boss);

            boss.setState("I'm back!");
            boss.removeNumber(one);
            boss.removeNumber(two);

            Subject lady = new Secretary();

            lady.resignNumber(one);
            lady.resignNumber(two);
            lady.setState("Boss has gone!");

            boss.setState("I'm back again!");

            Console.Read();
        }
Пример #6
0
 public Observer(string name, Secretary sub)
 {
     this.name = name;
     this.sub  = sub;
 }
Пример #7
0
 public StockObserver(string name, Secretary secretary)
 {
     _name      = name;
     _secretary = secretary;
 }
 public StockObserver(string name, Secretary sub) : base(name, sub)
 {
 }
Пример #9
0
 public NBAObserver(string name, Secretary sub) : base(name, sub)
 {
 }