• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why wrapper class is not suitable for callback framework?  RSS feed

 
praveen kumaar
Ranch Hand
Posts: 461
22
Android Chrome Eclipse IDE Google App Engine Java Notepad Oracle Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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”).Because a wrapped object doesn't know of its wrapper, it passes a reference to itself(this) and callbacks elude the wrapper. This is known as the SELF problem [Lieberman86].
This is a quote from "Effective Java".i don't understand what bloch intended to say in these lines and what is a callback framework.
can anyone please elaborate with an example?

Any reply will be appreciated.

kind regards,
Praveen.
 
Stephan van Hulst
Saloon Keeper
Posts: 7961
143
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




Now, if we do the following, what program output do you expect?
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving discussion as too difficult for this forum.
 
praveen kumaar
Ranch Hand
Posts: 461
22
Android Chrome Eclipse IDE Google App Engine Java Notepad Oracle Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi stephan,i am going busy for last few days so i just see your reply,thanks for it.

output would be "WrappedObject callback".but what is a disadvantage here,can you please elaborate in accordance with bloch's lines with your given example.
 
Stephan van Hulst
Saloon Keeper
Posts: 7961
143
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that even though we called doSomething() on the wrapper, the callback of the wrapped object got called, not the callback of the wrapper. This is what Joshua Bloch refers to when he says that "callbacks elude the wrapper".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!