Events in Java (Second try)
Well, I'm not that satisfied with the Signal/Slot system I described in a previous article. The reflection part of it makes me itch. So I gave it a second try...
First of all lets summarize the problems with the listener pattern:
- Two classes (The data container for the event and the listener interface) must be created for each event.
- At least three methods must be created for each event (Register, Unregister and Fire) in each class which is going to fire the event
So it's simply too much boiler-plate code and the goal is to put as much as possible of it into some library classes without losing any type-safety and without using reflection. I'm going to describe my solution in this article and again I will use the nonsense example of a citizen which drinks some beverage and a Big Brother which monitors it.
Continue reading "Events in Java (Second try)"