static void Main(string[] args) { //老板胡漢三 Boss huhansan = new Boss(); //看股票的同事 StockObserver tongshi1 = new StockObserver("魏關奼", huhansan); //看NBA的同事 NBAObserver tongshi2 = new NBAObserver("易管查", huhansan); huhansan.Update += new EventHandler(tongshi1.CloseStockMarket); huhansan.Update += new EventHandler(tongshi2.CloseNBADirectSeeding); //老闆回來 huhansan.SubjectState = "我胡漢三回來了!"; //發出通知 huhansan.Notify(); Console.Read(); }
static void Main(string[] args) { //老板胡漢三 Boss huhansan = new Boss(); //看股票的同事 StockObserver tongshi1 = new StockObserver("魏關奼", huhansan); //看NBA的同事 NBAObserver tongshi2 = new NBAObserver("易管查", huhansan); huhansan.Attach(tongshi1); huhansan.Attach(tongshi2); huhansan.Detach(tongshi1); //老闆回來 huhansan.SubjectState = "我胡漢三回來了!"; //發出通知 huhansan.Notify(); Console.Read(); }