A listener class links into a framework to allow interception of events.  Normally a listener must conform to an interface, which means new listeners can be time consuming to create, especially where lots of methods have to be implemented but only one is used.

Trap: The temptation is to reuse the same listener for different purposes, but don't do it.  Create new, specific listeners rather than one massive listener that can handle all cases, so code maintainability is assured.  

For example, a list item selection listener could easily be shared between two lists, as long as it checked which list created the event and acted accordingly. But the two lists are unrelated, so the two event handling blocks of code do not belong together.  Best to cut and paste yourself a new list selection listener class.

blog comments powered by Disqus