What is the difference bewteen handler and callback function?

277 Views Asked by At

In my current project, there are lots of networking code, and it use the event handler to handle the input message. Is this mechanism different with the call back function ?

2

There are 2 best solutions below

0
On

Typically not much. The handler is usually used in the context of a UI application where the UI control will call the handler to handle a UI event. The callback function is traditionally used from the C days (Function pointers) and also in the C++ (Functors) world.

0
On

As a general concept I would say that the call back functions are primarily used for Asynchronous execution. Where for example, client side function must look something up on the server and it may take a while. So instead of blocking it says :"Call back at this number (myCallBackFunction) when you are done looking up stuff on the server".

Now event handlers are just that: they handle some predefined events. Usually they wait for users to do something like click a button and then they spring into action. They typically but not necessarily expect some sort of input.

Hope this helps.