Frameworks – What Are Callback Frameworks?

frameworks

I am reading Effective Java and it has the following sentence.

The disadvantages of wrapper classes are few. One caveat is that wrapper
classes are not suited for use in callback frameworks, wherein objects pass selfreferences
to other objects for subsequent invocations (“callbacks”).

Now what is a callback framework ? Can you point me to an example of call back framework ?

Best Answer

Most GUI frameworks, and, SAX (Streaming XML) XML parsers use callbacks.

The basic pattern is that you pass an instance of a handler class (or sometimes just a method reference) when you initialize another class. When a specific event occurs the "handler" class is called to deal with the event.

This is typically how you get your code to run when a button on a GUI is pressed.

Related Topic