观察者设计模式
public class UserObserver
{
//观察者
public interface IUserObserver
{
void UserNotify(object anObject);
}
public interface IUserObservable
{
void UserRegister(IUserObserver anObserver);
void UserUnRegister(IUserObserver anObserver);
}
public class UserObservableImpl : IUserObservable
{
protected static Hashtable _userObserverContainer = new Hashtable();
public void UserRegister(IUserObserver anObserver)
{
_userObserverContainer.Add(anObserver, anObserver);
}
public void UserUnRegister(IUserObserver anObserver)
{
_userObserverContainer.Remove(anObserver);
}
public void NotifyObservers(object anObject)
{
foreach (IUserObserver anObserver in _userObserverContainer.Keys)
{
anObserver.UserNotify(anObject);
}
}
}
}