Java API design antipattern and tip
By vbkraemer on Jul 27, 2007
The Antipattern: Don't Create an Event Object for Your Listener Interface's Methods
I discovered this while trying to implement against a Listener interface that just sent in the "interesting" parts of the event... A String or two.
I needed to find out the source of the event (which is a pretty standard member of an Event interface), so that I could react to the event. This is easy to resolve by creating the listener with an additional member for the "expected" source. Or it is easy to resolve until you try to garbage collect these listeners that know their source...
An Event/Listener pair helps your API mature gracefully. Additional members/accessors can get added to the Event side of the interface without requiring changes in code that implements the Listener, unless the listener wants to USE that new member/accessor.
In the interest of transparency and honesty; I have to admit that I helped review and approve the Listener interface that lead to this entry. It just goes to show the value of having to write REAL code against an interface before you say, "Oh. That looks fine."