BrianMc1958
asked on
NEWBIE: Do events and delegates inform, or do?
Dear Experts,
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?".
Thanks!
BrianMc1958
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?".
Thanks!
BrianMc1958
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you, everybody. That helps. And I'll post a follow-up...
--BrianMc1958
--BrianMc1958
ASKER
The subscriber isn't really saying, "When this happens, TELL me". The subscriber is saying, "When this happens, DO this".
Is that right?