# Easy tip for ChangeListener hygiene

**URL:** <https://forum.juce.com/t/easy-tip-for-changelistener-hygiene/41224>\
**Category:** General JUCE discussion\
**Created:** [August 14, 2020, 2:14pm UTC](https://forum.juce.com/t/easy-tip-for-changelistener-hygiene/41224 "2020-08-14T14:14:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![LiamG](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/liamg/32/6844_2.png) [@LiamG](https://forum.juce.com/u/LiamG)\
**Post date:** [August 14, 2020, 2:14pm UTC](https://forum.juce.com/t/easy-tip-for-changelistener-hygiene/41224/1 "2020-08-14T14:14:09Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![chkn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/chkn/32/3862_2.png) [@chkn](https://forum.juce.com/u/chkn)\
**Post date:** [August 14, 2020, 3:47pm UTC](https://forum.juce.com/t/easy-tip-for-changelistener-hygiene/41224/2 "2020-08-14T15:47:32Z")

</div>

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

> [@Scoped-Listeners / Modernize listeners](https://forum.juce.com/t/scoped-listeners-modernize-listeners/23742):
>
> I’ve made this little class, and it really revolutionised my programming style. Its a scoped listener, and very easily combines the listener (old-school) functionality with the ability to attach std::function lambdas to it (a more modern approach). It’s not a very sophisticated, its very plain and simple. Example: class TestComponent : public Component { public: TestComponent( ColourSelector\* selector, MidiKeyboardComponent\* keyboard ) { // attach updateUI to the ChangeBroadcaster of Col…
