public static void Run() { Console.WriteLine("This real-world code demonstrates the Observer pattern in which registered investors are notified every time a stock changes value.\n"); IBM ibm = new IBM("IBM", 120.00); ibm.Attach(new Investor("Sorros")); ibm.Attach(new Investor("Berkshire")); ibm.Price = 120.10; ibm.Price = 121.00; ibm.Price = 120.50; ibm.Price = 120.75; /* * Notified Sorros of IBM's change to $120.10 * Notified Berkshire of IBM's change to $120.10 * * Notified Sorros of IBM's change to $121.00 * Notified Berkshire of IBM's change to $121.00 * * Notified Sorros of IBM's change to $120.50 * Notified Berkshire of IBM's change to $120.50 * * Notified Sorros of IBM's change to $120.75 * Notified Berkshire of IBM's change to $120.75 */ }
public static void Main() { // Create IBM stock and attach investors IBM ibm = new IBM("IBM", 120.00); ibm.Attach(new Investor("Sorros")); ibm.Attach(new Investor("Berkshire")); // Fluctuating prices will notify investors ibm.Price = 120.10; ibm.Price = 121.00; }
static void Main(string[] args) { IBM ibm = new IBM("IBM", 120); ibm.Bagla(new Yatirimci("Sorros")); ibm.Bagla(new Yatirimci("Berkshire")); ibm.Fiyat = 120; ibm.Fiyat = 121.00; ibm.Fiyat = 120.50; ibm.Fiyat = 120.75; }
internal static void Main() { // Create IBM stock and attach investors var ibm = new IBM("IBM", 120.00); ibm.Attach(new Investor("Sorros")); ibm.Attach(new Investor("Berkshire")); // Fluctuating prices will notify investors ibm.Price = 120.10; ibm.Price = 121.00; ibm.Price = 120.50; ibm.Price = 120.75; }
static void Main(string[] args) { IBM ibm = new IBM("IBM", 120.00); ibm.Attach(new Investor("Sorros")); ibm.Attach(new Investor("Berkshire")); ibm.Price = 120.10; ibm.Price = 121.00; ibm.Price = 120.50; ibm.Price = 120.75; }
static void Main(string[] args) { Console.WriteLine("Hello Observer design pattern!"); var stockIBM = new IBM("IBM", 100); var investors = new List <IInvestor>() { new Investor("Investor A"), new Investor("Investor B") }; stockIBM.AddInvestor(investors); stockIBM.Price += 100; }
public static void Run() { Console.WriteLine("Observer Real World Practice"); IBM ibm = new IBM("IBM", 120.00); ibm.Attach(new Investor("Sorros")); ibm.Attach(new Investor("Berkshire")); ibm.Price = 120.10; ibm.Price = 121.00; ibm.Price = 120.50; ibm.Price = 120.75; }
/// <summary> /// Entry point into console application. /// </summary> static void Main() { // Create IBM stock and attach investors IBM ibm = new IBM("IBM", 120.00); ibm.Attach(new Investor("Sorros")); ibm.Attach(new Investor("Berkshire")); // Fluctuating prices will notify investors ibm.Price = 120.10; ibm.Price = 121.00; ibm.Price = 120.50; ibm.Price = 120.75; // Wait for user Console.ReadKey(); }
static void Main(string[] args) { IBM ibm = new IBM(); Apple apple = new Apple(); Mobile mobile = new Mobile(); DisplayBoard displayBoard = new DisplayBoard(); ibm.RegisterObserver(mobile); apple.RegisterObserver(displayBoard); // ibm.CallbackStockPriceChangeDelegate = PrintCallback; ibm.SetPrice(11); apple.SetPrice(12); Console.ReadLine(); }
public static void Main(string[] args) { IBM ibm = new IBM("IBM", 120.00); ibm.Attach(new Investor("Sorros")); ibm.Attach(new Investor("Berkshire")); // Fluctuating prices will notify investors ibm.Price = 120.10; ibm.Price = 121.00; ibm.Price = 120.50; ibm.Price = 120.75; Console.ReadKey(); }
static void Main(string[] args) { // Create IBM stock and attach investors IBM ibm = new IBM("IBM", 120.00); ibm.Attach(new Investor("Sorros")); ibm.Attach(new Investor("Berkshire")); // Fluctuating prices will notify investors ibm.Price = 120.10; ibm.Price = 121.00; ibm.Price = Convert.ToDouble(Console.ReadLine()); // Wait for user Console.ReadKey(); }
static void Main() { // First example ConcreteSubject s = new ConcreteSubject(); s.Attach(new ConcreteObserver(s, "x")); s.Attach(new ConcreteObserver(s, "y")); s.Attach(new ConcreteObserver(s, "z")); s.SubjectState = "abc"; s.Notify(); IBM ibm = new IBM("IBM", 120.00); ibm.Attach(new Investor("Sorros")); ibm.Attach(new Investor("Berkshire")); ibm.Price = 120.10; ibm.Price = 121.00; ibm.Price = 120.50; ibm.Price = 120.75; ibm.Notify(); // Second example BaggageHandler provider = new BaggageHandler(); ArrivalsMonitor observer1 = new ArrivalsMonitor("BaggageClaimMonitor1"); ArrivalsMonitor observer2 = new ArrivalsMonitor("SecurityExit"); provider.BaggageStatus(712, "Detroit", 3); observer1.Subscribe(provider); provider.BaggageStatus(712, "Kalamazoo", 3); provider.BaggageStatus(400, "New York-Kennedy", 1); provider.BaggageStatus(712, "Detroit", 3); observer2.Subscribe(provider); provider.BaggageStatus(511, "San Francisco", 2); provider.BaggageStatus(712); observer2.Unsubscribe(); provider.BaggageStatus(400); provider.LastBaggageClaimed(); // Third example var weatherData = new WeatherData(); var forecastDisplay = new ForecastDisplay(weatherData); var heatIndexDisplay = new HeatIndexDisplay(weatherData); weatherData.setMeasurements(80, 65, 30.4f); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); IBM ibm = new IBM("IBM", 120.00); ibm.Attach(new Investor("Sorros")); ibm.Attach(new Investor("Berkshire")); // Fluctuating prices will notify investors ibm.Price = 120.10; ibm.Price = 121.00; ibm.Price = 120.50; ibm.Price = 120.75; // Wait for user Console.ReadKey(); }
internal static void Main() { // Create IBM stock and attach investors var ibm = new IBM("IBM", 120.00); var sorros = new Investor("Sorros"); ibm.Attach(sorros); ibm.Attach(new Investor("Berkshire")); // Fluctuating prices will notify investors ibm.Price = 120.10; ibm.Price = 121.00; ibm.Detach(sorros); ibm.Price = 120.50; ibm.Attach(sorros); ibm.Price = 120.75; }
static void Main(string[] args) { IBM ibm = new IBM("IBM", 120.00); ibm.Attach(new Investor("Tam")); ibm.Attach(new Investor("Minh")); ibm.Attach(new Investor("Tri")); ibm.Detach(new Investor("Minh")); // Fluctuating prices will notify investors ibm.Price = 120.10; ibm.Price = 121.00; ibm.Price = 120.50; ibm.Price = 120.75; // Wait for user Console.ReadKey(); }
/// <summary> /// Entry point into console application. /// </summary> static void Main() { // Create IBM stock and attach investors var ibm = new IBM(120.00); // Attach 'listeners', i.e. Investors ibm.Attach(new Investor { Name = "Sorros" }); ibm.Attach(new Investor { Name = "Berkshire" }); // Fluctuating prices will notify listening investors ibm.Price = 120.10; ibm.Price = 121.00; ibm.Price = 120.50; ibm.Price = 120.75; // Wait for user Console.ReadKey(); }