In C# we attach an event handler like this:
form1.Click += new EventHandler(form1_Click);
What is the significance of the “plus” sign? I know we can attach many eventhandlers for a control and hence the += syntax makes sense. But I think I should also be able to write just this:
form1.Click = new EventHandler(form1_Click);
so that i can override all the previous handlers and attach only the last one, but that wouldnt compile. Naturally I think += operator should work as if it is for strings and ints. What is the design principle for forcing += for handlers? In other words why cant i write just = ?
In this article, please, have a look at Publishing and Subscribing section.
So, you are a subscriber, you are not concerned to influence the list of those, who has already subscribed. It’s in the publishers competence.
If you say it’s up to a programmer, than you could develop your “publisher”-classes so that they could provide some public method, giving an opportunity to any subscriber to reset some event subscription. In the framework it is prohibited by design. This is also a decision by certain programmers.