static void Main(string[] args) { //前臺小姐童子喆 Secretary tongzizhe = new Secretary(); //看股票的同事 StockObserver tongshi1 = new StockObserver("魏關奼", tongzizhe); //看NBA的同事 NBAObserver tongshi2 = new NBAObserver("易管查", tongzizhe); //前臺記下了兩位同事 tongzizhe.Attach(tongshi1); tongzizhe.Attach(tongshi2); //發現老闆回來 tongzizhe.SecretaryAction = "老闆回來了!"; //通知兩個同事 tongzizhe.Notify(); Console.Read(); }
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(); }