LM Tech's blog

Software Architecture & Design Patterns

A callback is a reference to a portion of executable code, that is passed as an argument to other code.
Using callback, for instance, a server program can notify to a caller when the requested operation ends. The callback paradigm can also be used instead of the Observer Design Pattern. In Microsoft .Net Framework, callbacks are implemented using delegates that provides type-safe function pointer.

A delegate is declared using the delegate key-word:

public delegate void OperationCallbackDelegate(int value);

In the observer design pattern an object (the observable) mantain a list of its dependents (the observers) and notifies them when its state changes by calling a method on each registered subscribers. More...