Re: Reasoning behind the EventHandler(object, EventArgs) signature

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I guess for the same reasons that any good architect will impose some sort of order on any framework they design.

The signature reassures the developer that a certain behaviour is expected and that the sender of the event and some kind of event argument, either raw or derived, will be provided. A void return type is also imposing order and suggesting that info will be passed back in the event arguments.

Creating your own delegates is perfectly acceptable but, if you were writing any sort of commercial software, the choice would be nonsense because it wouldn't fit with the plan.

Systems that use reflection to discover the capabilities of a component, and there are lots of them these days, are also aware of the signature so things like databinding use these events in the data change notification system.

You would be strongly advised not to break what doesn't need fixing.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





John B wrote:
What is the reasoning for recommending that all events have the signature EventHandler(object sender, EventArgs e).
Obviously I can create a custom delegate
delegate void FooHandler(string foo)
and event FooHandler FooHappened

What are the benefits of creating derived eventargs classes for each event instead of creating the delegate which is much easier IMO.

Am I missing something?

Cheers
JB
.



Relevant Pages

  • How to: Promote Your Website
    ... Design a signature for your email that sells your book. ... You’ll find sites that will review your book, interview you, publish your articles, maybe even leads for publishing your book. ... Also pay attention to their format; these, too, may be places where you can get interviews, reviews, and have your articles published. ... Write them when someone responds to your autoresponder, write them when someone publishes a review or an interview, write them when someone does you a favor, write, write, write. ...
    (microsoft.public.windowsxp.newusers)
  • how to: book promotions
    ... Design a signature for your email that sells your book. ... You’ll find sites that will review your book, interview you, publish your articles, maybe even leads for publishing your book. ... Also pay attention to their format; these, too, may be places where you can get interviews, reviews, and have your articles published. ... Write them when someone responds to your autoresponder, write them when someone publishes a review or an interview, write them when someone does you a favor, write, write, write. ...
    (misc.writing)
  • Re: Newbie Delegate Question
    ... public void ShowMessageOnForm ... different delegate for each. ... the methods may require a signature change while the other does not. ... if a delegate is to hold references to "multiple ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: What Do You See ?
    ... You can have OE sort on anything you want and you don't have to go to any ... If I click on the "Insert Signature" icon on the toolbar it will insert this ... If I'm in the email portion of OE and click on the "Insert Signature" icon on ...
    (rec.sport.billiard)
  • Re: Newbie Delegate Question
    ... Are you saying you want to change the signature in one place (the ... are used with that delegate to have the same signature? ... So if you think of the delegate as being a reference to some ... public class WriteLogEventHandler: EventArgs ...
    (microsoft.public.dotnet.languages.csharp)