NEWBIE: Do events and delegates inform, or do?
Posted on 2006-05-05
I'm trying to understand the basics of delegates and events in C#.
Assume I have two classes which interact with a delegate/event model.
ButtonClass: Encapsulates a button, can be clicked.
CaresAboutClicksClass: Does something when the button is clicked.
I had (vaguely) assumed that when ButtonClass registers a click, it somehow just broadcasts this information, and CaresAboutClicksClass somehow hears the broadcast--perhaps with an assist from the .NET runtime.
What I'm reading seems to say, though, that CaresAboutClicksClass actually passes a METHOD--which is now a full-fledged object--to ButtonClass, initially. Then, when ButtonClass registers a click, it doesn't somehow just TELL CaresAboutClicksClass that a click happened. ButtonClass actually INVOKES the METHOD DIRECTLY. CaresAboutClicksClass doesn't actually DO anything at that point.
Is that right?
If it is right, does it make any sense to ask "where is this method being called FROM?".