コード例 #1
0
        /// <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("Marlon Santos"));
            ibm.Attach(new Investor("John Smith"));

            Dell dell = new Dell("Dell", 200.00);

            dell.Attach(new Investor("John Smith"));
            dell.Attach(new Investor("Marlon Santos"));

            // Fluctuating prices will notify investors
            ibm.Price = 120.10;
            ibm.Price = 121.00;
            ibm.Price = 120.50;
            ibm.Price = 120.75;

            dell.Price = 201.00;
            dell.Price = 200.50;

            // Wait for user
            Console.ReadKey();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: rvilela7/CsStuff
        static void Main()
        {
            IBM ibm = new IBM("IBM", 120.00);
            TP  TP  = new TP("TP", 10.00);

            Investor Jonhy = new Investor("João");
            Investor Rui   = new Investor("Rui");

            ibm.Attach(Rui);
            ibm.Attach(Jonhy);
            ibm.Attach(new Investor("Miguel"));
            ibm.Attach(new Investor("Aga"));
            TP.Attach(Rui);

            ibm.Price = 120.10;
            ibm.Price = 121.00;
            ibm.Price = 120.50;
            TP.Price *= 2;

            ibm.Detach(Jonhy);

            ibm.Price = 120.75;
            TP.Price *= 2;

            Console.ReadKey();
        }
コード例 #3
0
        public void Main()
        {
            var ibm = new IBM();

            ibm.Attach(new Investor("Sorros"));
            ibm.Attach(new Investor("Berkshire"));

            ibm.Price = 120.10m;
            ibm.Price = 121.00m;
            ibm.Price = 120.50m;
            ibm.Price = 120.75m;
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: Mayurbanta/DesignPatterns
        static void Main(string[] args)
        {
            Console.WriteLine("Observer Pattern through Go4");

            IInvestor User1 = new Investor("User1");
            IInvestor User2 = new Investor("User2");
            IBM       iBM   = new IBM(10, "IBM");

            iBM.Register(User1);
            iBM.Register(User2);
            iBM.Price = 20;
        }
コード例 #5
0
        static void Main(string[] args)
        {
            //Define a one - to - many dependency between objects so that when one object changes state,
            //all its dependents are notified and updated automatically.
            IBM ibm = new IBM("IBM", 120);

            ibm.Attach(new Investor("Umesh"));
            ibm.Attach(new Investor("Lakshmi"));

            ibm.Price = 123;
            ibm.Price = 127;
            ibm.Price = 130;
            Console.ReadLine();
        }
コード例 #6
0
        static void Main(string[] args)
        {
            IBM ibm = new IBM("IBM", 120.0);

            Investor investor1 = new Investor("John");
            Investor investor2 = new Investor("Jack");
            Investor investor3 = new Investor("Emily");
            Investor investor4 = new Investor("Scarlett");

            ibm.AddAllListeners(investor1, investor2, investor3, investor4);

            ibm.CalculatePriceChange(130.0);

            Console.ReadKey();
        }
コード例 #7
0
        private static void Main(string[] args)
        {
            // Create IBM stock and attach investors
            IBM ibm = new IBM(120.00);

            ibm.Subscribe(new Investor("Rajiv"));
            ibm.Subscribe(new Investor("Ranjan"));

            // Fluctuating prices will notify investors
            ibm.Price = 120.10;
            ibm.Price = 120.10;
            ibm.Price = 120.50;
            ibm.Price = 120.75;

            Console.ReadKey();
        }
コード例 #8
0
        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 = 120.50;
            ibm.Price = 120.75;

            Console.ReadKey();
        }
コード例 #9
0
        static void Main(string[] args)
        {
            CultureInfo.CurrentCulture = new CultureInfo("en-US");

            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;

            Console.ReadKey();
        }
コード例 #10
0
        public static void Main(string[] args)
        {
            // 创建投资者对象
            Investor m = new Investor("Mike");
            Investor b = new Investor("Bob");

            // 创建 IBM stock对象并添加投资者
            IBM ibm = new IBM("IBM", 120.00);

            ibm.Attach(m);
            ibm.Attach(b);

            // 改变股票价格,将会自动通知投资者
            ibm.Price = 120.10;
            ibm.Price = 121.00;
            ibm.Price = 120.50;
            ibm.Price = 120.75;
        }
コード例 #11
0
        static void Main(string[] args)
        {
            // Creamos un medidor de sensores
            ISubject sensores = new MedidorSensores(20, 380, 200);

            // Creamos dos observers: un display y un emisor de alertas.
            // Se realiza la suscripcion a traves del constructor
            IObserver display = new ObserverDisplay(sensores);
            IObserver alerta  = new ObserverAlerta(sensores);

            // Modificamos valores del subject. Los observers son automaticamente informados
            // y actuaran automaticamente
            ((MedidorSensores)sensores).NivelAceite            += 10;
            ((MedidorSensores)sensores).NivelAceite            += 10;
            ((MedidorSensores)sensores).NivelAgua              += 100;
            ((MedidorSensores)sensores).NivelPresionNeumaticos -= 50;
            ((MedidorSensores)sensores).NivelAceite            += 10;
            ((MedidorSensores)sensores).NivelAgua              += 100;
            ((MedidorSensores)sensores).NivelAgua              += 100;

            Console.WriteLine("\n Inventario \n");

            // 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;

            Console.ReadKey();
        }