I\'ve just started getting to grips with event driven programming and I\'m findi
ID: 649959 • Letter: I
Question
I've just started getting to grips with event driven programming and I'm finding delegates and events to be very useful. Since starting to see the potential I've began using them all the time to solve problems such as updating displays between controls and calling stored procedures following updates etc.
I'm starting to use them so frequently that I'm creating and subscribing to events more than I'm actually calling methods manually within the code. Are there any rules to follow in order to know when an event should be used or just a plain old simple function call?
Any advice is greatly appreciated.
Thanks
Explanation / Answer
For me the distinction between using an event and calling a method is for proper separation of concern.
When you call a method, the caller know what method is being called. When you raise an event, the raiser doesn't know who's listening (if anyone at all).
A button control is an excellent example of when an event is appropriate, because a button control doesn't and shouldn't be tied to what it does.
Basically with an event, the actual method that gets called is a variable rather than a constant. This makes it more flexible, but at the same time if it doesn't need to change, it can make the code more complicated to follow.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.