static void Main(string[] args) { //sample 2 var messagePublisher = new MessageSubject(); var postTitle = new Post() { Message = "this is new post" }; var emailObserver = new EmailObserver(); var telegramObserver = new TelegramObserver(); var smsObserver = new SMSObserver(); messagePublisher.MessagePublisher += emailObserver.onEmailObserver; messagePublisher.MessagePublisher += telegramObserver.onTelegramObsever; messagePublisher.MessagePublisher += smsObserver.onSMSObsever; messagePublisher.onPublisher(postTitle); //=================================================================== //sample 1 //var person = new Person(); //person.FallsIll += CallDoctor; //person.CatchACold(); Console.ReadKey(); }
static void Main(string[] args) { var pushMessageSupplier = new PushMessageSupplier(); var observer1 = new EmailObserver("John"); var observer2 = new EmailObserver("Steve"); var disposable1 = pushMessageSupplier.Subscribe(observer1); var disposable2 = pushMessageSupplier.Subscribe(observer2); pushMessageSupplier.SendMessages(new Email("Jane", "Hi boys.")); disposable1.Dispose(); pushMessageSupplier.SendMessages(new Email("Jane", "I am Jane.")); }
static void Main(string[] args) { var emailObserver = new EmailObserver(); var smsObserver = new SMSObserver(); DocketData subject = new DocketData(); subject.RegisterObserver(emailObserver); subject.RegisterObserver(smsObserver); Docket efhDocket = new Docket() { DocketId = 1, DocketNumber = "123", DocketText = "Docket filed for the case Energy Future Holdings", FileDate = new DateTime(2017, 6, 28) }; subject.NewDocketAdded(efhDocket); Docket daiDocket = new Docket() { DocketId = 2, DocketNumber = "456", DocketText = "Docket filed for the case Delta Airlines", FileDate = new DateTime(2017, 6, 29) }; subject.NewDocketAdded(daiDocket); subject.RemoveObserver(emailObserver); Docket cscDocket = new Docket() { DocketId = 3, DocketNumber = "89", DocketText = "Docket filed for the case Corporation Services", FileDate = new DateTime(2017, 7, 29) }; subject.NewDocketAdded(cscDocket); Console.ReadLine(); }