Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference, if any, between event handler and event listener?

Tags:

events

client

We read here and there, event handler, event listener... event handler/listener... object handler... it's a mass confusion that a newbie 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

like image 570
MEM Avatar asked Aug 26 '10 10:08

MEM


2 Answers

Listener:
The intermediary, connecting object between a source of activity and a reaction to that activity.
A listener object's life cycle:

  1. Subscribe a handler to be called when an event is published from an event source.
  2. "Listen" for an event to happen on the event source.
  3. 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.

like image 147
Pup Avatar answered Sep 25 '22 16:09

Pup


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

like image 42
Kangkan Avatar answered Sep 24 '22 16:09

Kangkan