Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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 ?

share|improve this question
    
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?" –  bjarkef 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
add comment

2 Answers

up vote 0 down vote accepted

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.

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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