public class EventNotifier {
private InterestingEvent ie;
private boolean somethingHappened ;
public EventNotifier() {
somethingHappened = true ;
}
public void setInterestingEvent(InterestingEvent ie){
this.ie = ie ;
}
public void doWork(){
if(somethingHappened){
ie.interestingEvent();
}
}
}
下面做一下测试.
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
CallMe cm = new CallMe();
CallYou cy = new CallYou();
EventNotifier en = new EventNotifier();