标签:des style blog io color ar sp for div
void Main() { Subject s = new Subject(); s.Add(new ObserverA(s)); s.Add(new ObserverB(s)); s.Notify(); } class Subject { List<Observer> observers = new List<Observer>(); public void Add(Observer o){ observers.Add(o);} public void Remove(Observer o){ observers.Remove(o);} public void Notify(){ foreach (var observer in observers) { observer.Show(); } } } abstract class Observer{ protected Subject subject; public Observer(Subject s){ subject = s; } public abstract void Show(); } class ObserverA:Observer{ public ObserverA(Subject s):base(s){} public override void Show(){} } class ObserverB:Observer{ public ObserverB(Subject s):base(s){} public override void Show(){} }
DesignPattern_Behavioral_Observer
标签:des style blog io color ar sp for div
原文地址:http://www.cnblogs.com/rammderek/p/4102939.html