First of all, it is important to note that leadership is not law.
All hell (or the equivalent of a programmer) will not break if you do not follow the recommendations.
Thus, feel free to modify the signature of your events accordingly.
However, it is also important to know why these recommendations were added to begin with, and one major part of the answers to this question is version control.
Having the following two parts and only those two parts:
- The source of the event that was introduced as “generic” as possible (note that the event signatures were developed long before the correct generics were introduced into the system, so
object is as generic as it might be) - Object inheriting from
EventArgs
then you develop code that is more resilient to change.
First of all, since you are not allowed to add or remove parameters, all future versions of your event will still only have sender and e .
Secondly, there is a second part with respect to the parameter e . If you decide to change the signature of the event handler in the new version of the class library by changing the type of the parameter e , you should make it more specific by dropping from your current type and passing to the descendant instead.
The reason for this is because existing code that is already processing your current (old) type will still work.
Thus, all the reasoning underlying the guide is as follows:
- Stay consistent (as others have pointed out)
- Design for the future (making sure that code written against version X of your class still works when you release version X + 1 without manually modifying this code)
Now, if any of these questions are not worrying about your case, feel free to follow the recommendations.
In fact, you can make an event from Action , and it will work fine.
Lasse Vågsæther Karlsen
source share