Link to home
Start Free TrialLog in
Avatar of BrianMc1958
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
Avatar of BrianMc1958
BrianMc1958

ASKER

A shorter version of the same question:

The subscriber isn't really saying, "When this happens, TELL me".  The subscriber is saying, "When this happens, DO this".

Is that right?
ASKER CERTIFIED SOLUTION
Avatar of pallosp
pallosp

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you, everybody.  That helps.  And I'll post a follow-up...

--BrianMc1958