3

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 ?

  • This sentence seems to be a bit out of context. Could you tell us in which section this sentence appears ? – barjak Nov 2 '11 at 10:05
  • Additionally: "Why are wrapper classes not suited for use in callback frameworks?" – Bjarke Freund-Hansen Nov 3 '11 at 7:45
  • 1
    @barjak this is from Chapter 4 (Classes and Interfaces), page 85. books.google.com/… – Steve Jackson Nov 3 '11 at 11:42
  • Ok, so the term "wrapper class" here refers to a class that uses composition instead of inheritance. And the caveat that is discussed in this paragraph happens when the "wrapped" class implements a callback interface and registers himself as a callback object. Personnaly, I think it's a bad style for a class to implement callback interfaces, anyway. So the caveat goes away... – barjak Nov 3 '11 at 14:17
  • If you mean the frameworks having callback classes , here is the list of frameworks having that - javasearch.buggybread.com/home.php?keyword=callback – Vivek Vermani Feb 15 '16 at 20:36
4

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.

2

many gui frameworks are callback frameworks (functions are called as events happen)

any time you have to provide handlers for events you are using a callback framework

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.