Saturday, June 27, 2009

Callback vs Listener

The Callback pattern is variation of the Command pattern [Gamma], where the Receiver itself is a concrete expression of the Command (Callback) class and is registered with the Subject. When an event of interest occurred, the Subject "calls back" the Receiver via the registered concrete Callback subclass.

The Listener implements the Observer pattern [Gamma], where the Listener is the Observer and is also registered with the Subject.

A Subject may have multiple Listeners, while it can only have one Callback Receiver. However, multiple Listeners may be implemented as a "callback list".

Java implements Listeners as a callback list. It implements a "push" model of the Observer pattern where additional information is supplied as an Event argument tailored to the Listener.


No comments:

Post a Comment