|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ChapterTwo
{
class WeatherStation
{
static void Main(/*string[] args*/)
{
#region Using the Custom Interface
WeatherData weatherData = new WeatherData();
CurrentConditionsDisplay currentDisplay = new CurrentConditionsDisplay(weatherData);
weatherData.SetMeasurements(80, 65, 30.4f);
weatherData.SetMeasurements(85, 70, 31.4f);
currentDisplay.RemoveObservation();
weatherData.SetMeasurements(75, 90, 35.4f);
#endregion
#region Using IObservable of .Net Framework
//Using .Net Frameowrk In-Built IObservable & IObserver Interfaces.
Console.WriteLine();
Console.WriteLine(".Net Style Observer Pattern");
Console.WriteLine();
// ONE PROVIDER
WeatherDataObservable provider = new WeatherDataObservable();
// MANY SUBSCRIBER
CurrentConditionsDisplayObserver subscriberOne = new CurrentConditionsDisplayObserver("First");
subscriberOne.Subscribe(provider);
CurrentConditionsDisplayObserver subscriberTwo = new CurrentConditionsDisplayObserver("Second");
subscriberTwo.Subscribe(provider);
CurrentConditionsDisplayObserver subscriberThree = new CurrentConditionsDisplayObserver("Third");
subscriberThree.Subscribe(provider);
provider.TrackWeather(new Weather(80, 65, 30.4f));
//subscriberOne.Unsubscribe();
provider.TrackWeather(new Weather(85, 70, 31.5f));
//subscriberTwo.Unsubscribe();
provider.TrackWeather(new Weather(75, 90, 33.3f));
//subscriberThree.Unsubscribe();
//provider.TrackWeather(null);
provider.EndTransmission();
#endregion
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Working in Software Development since 2007.
Work in .Net/VC++/COM.
work in Process Automation domain.