public DemoSubject()
            {
                var oo = new OperationObserver();

                // subject is both an observer and observable
                var market = new Subject <float>();

                // note also the overloads of this!
                market.Subscribe(this);
                //market.Subscribe(this); // it is possible to subscribe twice. All events will be duplicated.

                market.OnNext(123);
                market.Subscribe(oo);                 // late subscription
                market.OnNext(456);
                market.OnCompleted();

                market.OnNext(321.123f);                                          // this will not work
                Console.WriteLine($"market.HasObservers? {market.HasObservers}"); // nope
            }
Exemplo n.º 2
0
 //accept a new observer
 //note that this design pattern (Observer Pattern) is used to neatly transport information between loosely coupled objects
 public void addObserver(OperationObserver observer)
 {
     observers.Add(observer);
 }