Let's assume that I have a GWT application with many instances of Label (let's say hundreds of them), and a Button. When the user click on the Button, my application does the following:
- highlights every
Labelby making its background color green; - when the user moves the mouse on an highlighted
Label, its background becomes dark green, and the font turns white; - when the user moves the mouse out of an an highlighted
Label, its background reverts green, and the font reverts to black; - when the user clicks on an highlighted
Label, everyLabelis reverted to the original appearance (i.e. before the user clicked theButton).
In order to achieve the above behaviour I need to register MouseOverHandler, MouseOutHandler, and ClickHandler for every Label.
Let's say that I have a class MyHandler implementing all 3 handlers. From performance perspective, what is better?
- have one single instance of
MyHandlerand register it asMouseOverHandler,MouseOutHandler, andClickHandlerfor everyLabel - register a new instance of
MyHandlerasMouseOverHandler,MouseOutHandler, andClickHandlerfor everyLabel
Moreover, after the user has clicked an highlighted Label, I'm no longer interested in MouseOverEvent, MouseOutEvent, and ClickEvent from the labels. In this situation, is it better to unregister the instance(s) of MyHandler, or to keep them registered for the next time the user will click the Button?