观察者模式:
通知者:
public interface INotifier
{
public vod addObserver(IObserver o);
public void removeObserver(IObserver o);
public void notify();
}
public class NotifierA implements INotifier
{
List<IObserver> observers = new ArrayList<IObserver>();
public vod addObserver(IObserver o)
{
observers.add(o);
}
public void removeObserver(IObserver o)
{
observers.remove(o);
}
public void notify()
{
IObserver o = null;
for(int i = 0; i < observers.getItemCount(); i++)
{
o = (IObserver)observers.getItem(i);
o.update();
}
}
}
观察者:
public interface IObserver
{
public void update();
}
public class observerA implements IObserver
{
public void update()
{
//…………
}
}