MEM
MEM

Reputation: 31307

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 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

Upvotes: 5

Views: 667

Answers (2)

Pup
Pup

Reputation: 10516

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.

Upvotes: 4

Kangkan
Kangkan

Reputation: 15571

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

Upvotes: 1

Related Questions