C#设计模式之观察者模式实例讲解

2019-12-26 12:12:14王旭

            #endregion

            public void Update()
            {
                if (NotifyEvent != null)
                {
                    NotifyEvent(this);
                }
            }
        }

        // 具体订阅号类
        public class MyBlog : Blog
        {
            public MyBlog(string symbol, string info)
                : base(symbol, info)
            {
            }
        }

        // 具体订阅者类
        public class Subscriber
        {
            public string Name { get; set; }
            public Subscriber(string name)
            {
                this.Name = name;
            }

            public void Receive(Object obj)
            {
                Blog xmfdsh = obj as Blog;

                if (xmfdsh != null)
                {
                    Console.WriteLine("订阅者 {0} 观察到了{1}{2}", Name, xmfdsh.Symbol, xmfdsh.Info);