Events in Java
Java has no integrated event system but most classes in the Java Runtime uses the Listener Pattern for this. This pattern is pretty powerful and (when using Generics) completely type-safe but in the end it is still pain-in-the-ass. Think of a class which wants to send five different events. You have to write five listener interfaces and write at least 15 methods (five register methods, five unregister methods and five fire-event methods) and collections for all the listener objects which are registered. Depending on the type of events you may want to write five event classes which are used as containers for the event data. Lazy programmers therefor put all five events into the same listener interface so they only need one register/unregister/fire tripplet. But this requires the event receivers to implement all five listener methods even if they are interested in only one of them. So some genius invented the Adapter classes which already provide empty listener methods which can be extended by the event receiver. The whole thing is pretty annoying because it's so complicated to implement and to use.
So lets take a look at a different approach...
Continue reading "Events in Java"
Syndicated 2009-06-01 13:23:00 (Updated 2009-06-02 22:23:56) from K's cluttered loft