コード例 #1
0
        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();
        }
コード例 #2
0
 public FileObserver(NumberSequence ns, string path)
 {
     this._ns      = ns;
     this.filePath = path;
     this._ns.addObservers(this);
 }
コード例 #3
0
 public MeanObserver(NumberSequence ns)
 {
     this._ns = ns;
     this._ns.addObservers(this);
 }