I am creating an event-based API where a user can subscribe to an event by adding listener objects (as is customary in Java or C #). When an event is raised, all subscribers-subscribers are called with information about the event.
At first, I decided to prevent the addition of an event listener several times. If a listener is added that already exists in the listener collection, it is not added again. However, after thinking about it a little more, it seems that most event-based structures actually prevent this. Was my initial instinct wrong? I'm not sure where to go. I think I thought that preventing the addition of an existing listener would help avoid a common programming error. Again, it can also hide an error that will cause code to run several times when it shouldn't.
source
share