“Callback” is a term that refers to a coding design pattern available in any language that has pointers to functions, or pointers to analog functions (which is a kind of delegate)
In this template, you pass a pointer to a function of another function, so that inside the called function, it can “call back” the function that you passed to it. Thus, you can control a large chunk of the internal behavior of the method outside the method by passing pointers to different "callback" functions each time you call it ... An example of a callback is choosing a sorting algorithm that should be passed a pointer to a function that will be “compare” any arbitrary pair of objects in a sorted list to determine what happens before another. With one call to the sorting method, you can pass a callback function that compares by the name of the object, and another time passes a function that compares by the weight of the object or something else ...
The delegate, otoh, is specific. By a Net type that acts as a signature-specific container for a function pointer ... In managed .Net code, delegates are the only way to create and use a function pointer. Therefore, in .Net, you actually pass a delegate to make a callback ... But delegates can be used in scripts other than callbacks. (in particular, delegates can also be used to implement multithreading from a .Net thread pool)
Callbacks are also used to implement the observer pattern (implemented in .Net using events, which themselves are a special type of delegate)
Charles Bretana Nov 14 '08 at 17:58 2008-11-14 17:58
source share