Created
January 13, 2012 14:24
-
-
Save jdewind/1606469 to your computer and use it in GitHub Desktop.
Traditional Event Subscription/Listening
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ApplicationEvent { | |
public void invoke(Object value); | |
} | |
public class ApplicationEventListener implements ApplicationEvent { | |
private Application application; | |
public ApplicationEventListener(Application application) { | |
this.application = application; | |
this.application.addApplicationEventListener(this); | |
} | |
public void invoke(Object value) { | |
// handle event | |
} | |
} | |
public class Application { | |
private ArrayList<ApplicationEvent> events = new ArrayList<ApplicationEvent>(); | |
public void addApplicationEventListener(ApplicationEvent event) { | |
events.add(event); | |
} | |
public void postEvent() { | |
for (ApplicationEvent event : events) { | |
event.invoke(this); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment