Timeline for Delegate vs Interfaces-Any more clarifications available?
Current License: CC BY-SA 3.0
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Oct 25, 2011 at 8:03 | history | bounty awarded | CommunityBot | ||
| Oct 24, 2011 at 9:14 | comment | added | Steven Jeuris | @YamMarcovic: Second that, no idea why this got accepted. Plenty of better answers. Thanks for pointing out using an EventHandler is just a convention, I had no idea. :O | |
| Oct 24, 2011 at 5:55 | vote | accept | WinW | ||
| Nov 2, 2011 at 9:17 | |||||
| Oct 20, 2011 at 19:02 | history | edited | Carlo Kuip | CC BY-SA 3.0 | Removed last two options, replaced with link to article explaining |
| Oct 20, 2011 at 18:58 | comment | added | Carlo Kuip | Found a thread on this subject explaining important differences:bytes.com/topic/c-sharp/answers/252309-interface-vs-delegate | |
| Oct 20, 2011 at 16:37 | comment | added | Yam Marcovic | Firstly we were talking about delegates vs interfaces, not events vs interfaces. Secondly, making an event base itself on an EventHandler delegate is just a convention, and by no means mandatory. But again, talking about events here kind of misses the point. As for your second comment - exceptions aren't checked in C#. You're getting confused with Java (which incidentally doesn't even have delegates). | |
| Oct 20, 2011 at 15:32 | comment | added | Carlo Kuip | As for the reason why I think a method defined in an interface would make it easier to handle errors is having the compiler being able to check the exception types thrown from that method. I know it's not convincing evidence but maybe should be stated as preference? | |
| Oct 20, 2011 at 15:22 | comment | added | Carlo Kuip | In case of just the spec of a delegate you are right. In the case of event handling however(at least that's what my reference is pertaining to) you alway need to inherit form some kind of eventArgs to act as container for custom types, so instead of being able to safely test for a value you would always have to unwrap your type before handling the values. | |
| Oct 20, 2011 at 11:13 | comment | added | Yam Marcovic | 3. Why would delegates require more casting, and why is tighter coupling a benefit? 4. You don't have to use events to use delegates, and with delegates it's just like holding a method - you know it's return type and it's arguments' types. Also, why would a method declared in an interface make it easier to handle errors than a method attached to a delegate? | |
| Oct 20, 2011 at 9:58 | history | answered | Carlo Kuip | CC BY-SA 3.0 |