static void Main(string[] args) { TengXun tenXun = new TengXunGame("TenXun Game", "Have a new game published ...."); // 添加订阅者 tenXun.AddObserver(new Subscriber("Learning Hard")); tenXun.AddObserver(new Subscriber("Tom")); tenXun.Update(); Console.ReadLine(); }
private void button1_Click(object sender, EventArgs e) { Subscriber sub = new Subscriber("LearningHard"); TengXunGame txGame = new TengXunGame(); txGame.Subscriber = sub; txGame.Symbol = "Tengxun Game"; txGame.Info = "You have a news"; label1.Text = txGame.Update(); }
/// <summary> /// 客户端 /// </summary> public static void Dothis() { // 实例化订阅者和订阅号对象 Subscriber subscriber = new Subscriber("John"); TengXunGame Tengxun = new TengXunGame(); Tengxun.Subscriber = subscriber; Tengxun.Symbol = "Game New Conference"; Tengxun.Info = "Have a new game create by ..."; Tengxun.Update(); Console.ReadLine(); }
public void ReceiveAndPrintData(TengXunGame tengxunGame) { Console.WriteLine("Notified {0} of {1} is {2}'s", Name, tengxunGame.Symbol, tengxunGame.Info); }
public string ReceiveAndPrint(TengXunGame txGame) { return(string.Format("name={0}, symbol={1}, info={2}", Name, txGame.Symbol, txGame.Info)); }