Dilantha Seneviratne said:
Hi
Could someone advise me what a callback method is,
when and how they are developed and used.
A callback is a method that is executed by another method that has a
reference to the callback [in languages that support method pointers], or
its owning object. Keeping a reference in this way allows the caller to
execute [or 'call back'] the callback at some indeterminate future time.
A very simple example follows:
class Callee
{
...
void execute() { ... }
...
}
class Caller
{
...
public Caller(Callee cb) { this.cb = cb; }
...
void makeTheCallback() { cb.execute(); }
...
private cb;
}
...
public static void main(String[] args)
{
Caller ca = new Caller(new Callee());
...
if (...)
ca.makeTheCallback();
...
}
Probably the most common example of a callback in Java is the use of event
listeners in Swing. The programmer creates the callback / callee, registers
it with the relevant component, and the system 'calls it back' to handle the
event for which it has been registered [note this is a very rough
description, but should be enough to give you an idea].
I hope this helps.
Anthony Borla