What is the difference, if any, between event handler and event listener?
We read here and there, event handler, event listener... event handler/listener... object handler... it's a mass confusion that a new开发者_如何转开发bie like me can't tolerate.
Anyone to clarify this question: What is the difference, if any, between event handler and event listener ?
Thanks a lot, MEM
Listener:
The intermediary, connecting object between a source of activity and a reaction to that activity.
A listener object's life cycle:
- Subscribe a handler to be called when an event is published from an event source.
- "Listen" for an event to happen on the event source.
- Call the handler when it does.
The term "listener" can be deceiving because, in most implementations, it is not actively doing anything-- it simply functions as a stored association between an event and an event handler.
Handler:
An object (usually a function) that provides a behavior to run when a subscribed-to event is published.
(See Wikipedia's "Observer Pattern")
(See Wikipedia's "Event Handler")
Important Differences:
A listener reacts to an event source, e.g. keyboard or mouse.
A handler reacts to an event, e.g. key press or mouse click.
The event listener is basically a delegate that listens to the event. The delegate is used to write a handler if the programmer need to do something on a particular event. So for a particular event, the listener works as a trigger to trigger the actual handler code.
You can read about this here:
http://msdn.microsoft.com/en-us/library/aa645739%28VS.71%29.aspx
and
http://blog.monstuff.com/archives/000040.html
精彩评论