Easy tip for ChangeListener hygiene

I make constant use of the ChangeListener and ChangeBroadcaster classes, as I’m sure most people do. One of the challenges I’ve faced is keeping track of what is listening to what. Because the addChangeListener() method is inherited, it’s not easy to trace it in a debugger, nor can you really do a text search for it.

Today I decided to change all my ChangeBroadcasters to private inheritance, and add small inline functions to call addChangeListener() and removeChangeListener(). It makes for a bit of redundancy, but it also means that you can easily find out what attaches to a broadcaster class. You can also make the functions more descriptive, i.e. addListenerForNoteChange().

Hope this helps!

I made this little helper classes, and i use them still today, maybe its what you are looking after?

1 Like