Re: mucking with Event Definitions to get tighter coupling to Objects ?
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Sun, 03 Feb 2008 11:53:27 -0800
On Sun, 03 Feb 2008 10:31:21 -0800, Bill Woodruff <msnwsgroups@xxxxxxxxxxxxxx> wrote:
[...]
1. is what I am doing flat-out wrong/bad/blasphemy/poor coding in your
opinion ?
No, I wouldn't say so.
2. what issues could arise from not following the standard .NET event
Sender, EventArgs parameter order structure. I'm assuming there are issues
other than the developer has to carry a slightly more "heavy" weight mental
model.
The primary issue I see is the one that motivates the .NET convention: if you make the event delegate signature dependent on the class implementing the event, then you cannot write a handler that is compatible with multiple classes, generally speaking. One exception is if the event is declared in a base class, then of course you could have a single event handler method handle the same event for multiple derived classes.
This doesn't come up a lot, but it can. If it's of no concern to you, then I wouldn't worry about it too much.
The other issue is of course adhering to existing conventions. This is not one I personally worry too much about, but I know that others do and I don't fault them for it. This isn't a code-correctness issue so much as it is a potential maintenance and multi-person team issue. Having the exact same signature pattern for all events is helpful in making the code readable, because you can always look at a method and see right away that it's an event handler. That said, there are other clues in the method signature (for example, if the first parameter is always named "sender" and the second parameter's type always has the phrase "EventArgs" in it, then that's at least as powerful a clue).
3. if you would use a technique like this, in what scenarios would you use
it and why.
I can't think of any in which I'd specifically bother. That said, I'm sure that at least once I've written an event that doesn't share _any_ of the .NET convention (e.g. may not even include a sender or event data). It can be done, and if you feel it's important enough to do so, then don't let the convention stand in your way.
4. could this technique, by eliminating casts and lookups contribute any
real increase in speed or whatever in apps ? In other words, given you Can
use it, is it worth using ?
Not from a performance point of view, no. If your code's performance is bottlenecked by a cast, then it is already doing basically nothing and should be able to do that nothing extremely quickly. :)
many thanks for your examining and commenting on this. the code has
unusually long verbose variable names because I am writing it as an
educational tool to demonstrate an alternate way to Raise Events ...
I didn't even bother to look closely at the code. For what it's worth, if you're asking a question, post code that someone will actually read, and which includes _only_ the bare minimum required. In this particular instance, you could have simply posted the .NET convention, and an example of the delegate type for a non-compliant event. There was no need to post all that other stuff, and the more complex the code you post, the more likely someone will not read it, or will even ignore your entire post.
Pete
.
- Follow-Ups:
- Re: mucking with Event Definitions to get tighter coupling to Objects ?
- From: Ben Voigt [C++ MVP]
- Re: mucking with Event Definitions to get tighter coupling to Objects ?
- From: Bill Woodruff
- Re: mucking with Event Definitions to get tighter coupling to Objects ?
- References:
- mucking with Event Definitions to get tighter coupling to Objects ?
- From: Bill Woodruff
- mucking with Event Definitions to get tighter coupling to Objects ?
- Prev by Date: Re: mucking with Event Definitions to get tighter coupling to Objects ?
- Next by Date: Re: No way to encrypt with private key in C#?
- Previous by thread: Re: mucking with Event Definitions to get tighter coupling to Objects ?
- Next by thread: Re: mucking with Event Definitions to get tighter coupling to Objects ?
- Index(es):
Relevant Pages
|
Loading