What is a callback?
A callback is an application’s procedure registered for certain events. When these events occur, they are passed to and processed by the callback.
According to the HCI book, there are two programming models for building interactive applications: read-evaluation loop and notification based.
- Read-evaluation loop: the application takes in all the events passed over from the server, and employs certain mechanism (e.g., a switch statement) to process these events and decide what actions should follow.
- Notification based: the handling of events is partially outsourced to a notifier. The application first registers with the notifier about 1) what events it is interested at, and 2) for each of these events, what callback is associated. Then the notifier simply monitors events passed over from the server, sort them and pass the handles to different callbacks accordingly.
Read-evaluation loop can be cumbersome to program with as one is totally responsible for receiving, identifying and responding to all the possible events coming to the application. With notification based, this job is mostly taken over by the notifier. But the downside is the application – unlike in the case of read-evaluation loop – doesn’t have a direct control over events that come to it. More communication is required between the application and the notifier.