static void Main(string[] args) { #region Setup Source source = null; string filePath = "file.txt"; string observerFilePath = "observerFile.txt"; Console.WriteLine("Select source:"); int selectedSource = Convert.ToInt32(Console.ReadLine()); switch (selectedSource) { case 1: source = new KeyboardSource(); break; case 2: source = new FileSource(filePath); break; } NumberSequence ns = new NumberSequence(); ns.setSource(source); FileObserver od = new FileObserver(ns, observerFilePath); SumObserver os = new SumObserver(ns); AvgObserver oa = new AvgObserver(ns); MeanObserver om = new MeanObserver(ns); //ns.addObservers(od); //ns.addObservers(os); //ns.addObservers(oa); //ns.addObservers(om); #endregion ns.start(); Console.ReadKey(); }
public FileObserver(NumberSequence ns, string path) { this._ns = ns; this.filePath = path; this._ns.addObservers(this); }
public MeanObserver(NumberSequence ns) { this._ns = ns; this._ns.addObservers(this); }