close

http://en.wikipedia.org/wiki/Callback_%28computer_science%29




In computer programming, a callback is executable code that is passed as an argument to other code. It allows a lower-level software layer to call a subroutine (or function) defined in a higher-level layer.


Callbacks have a wide variety of uses. For example, imagine a
function that reads a configuration file and associates values with
options. If the options are identified by a hash,
writing it so that it takes a callback makes the function more
flexible: the user of it can use whatever hashing algorithm he wishes
and the function will continue to work, since it uses the callback to
turn option names into hashes; thus, callbacks allow the user of a
function to fine-tune it at runtime.

Another use is in error signaling. A Unix program, for example, might not want to terminate immediately when it receives SIGTERM; to make sure things get taken care of, it would register the cleanup function as a callback.

Callbacks may also be used to control whether a function acts or not: xlib allows custom predicates to be specified to determine whether a program wishes to handle an event.


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 UbuntuLinux 的頭像
    UbuntuLinux

    UbuntuLinux

    UbuntuLinux 發表在 痞客邦 留言(0) 人氣()