public void PublishNews(string name, string detail) { NewsEventArgs na = new NewsEventArgs(name, detail); /* If news arrived and ready to publish then call OnNewsArrival * method which will execute subscribed methods.*/ OnNewsArrival(na); }
/* If anyone subscribe for the notification then this method will * invoke each of the subscribed method and execute all. */ protected virtual void OnNewsArrival(NewsEventArgs args) { EventHandler <NewsEventArgs> newsHandler = NewsEvent; if (newsHandler != null) { newsHandler(this, args); } }
/* When news arrived if subscribe then execute this method.*/ private void PublishArrivedNews(object sender, NewsEventArgs na) { Console.WriteLine("Published:\n{0} news.", na.Title); }
/* When news arrived if subscribe then execute this method.*/ private void ReviewOnArrivedNews(object sender, NewsEventArgs na) { Console.WriteLine("Reviewed:\n{0},\t{1}", na.Title, na.Detail); }