Пример #1
0
        static void Main()
        {
            Subject subject = new Subject();

            Observer hexObserver   = new HexObserver(subject);
            Observer octObserver   = new OctObserver(subject);
            Observer romanObserver = new RomanObserver(subject);

            while (true)
            {
                Console.Write("Input integer: ");
                string input = Console.ReadLine();

                int state;
                if (int.TryParse(input, out state))
                {
                    subject.State = state;
                }
                else
                {
                    Console.WriteLine("Invalid integer.");
                }

                Console.WriteLine();
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            //Reference: https://sourcemaking.com/design_patterns/observer
            Input input = new Input();
            MultiplierObserver multiplierObserver = new MultiplierObserver(input);
            HexObserver        hexObserver        = new HexObserver(input);

            input.Value = 10;
            input.Value = 90;

            Console.Read();
        }