• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

concep of callback

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
could anyone give me a clear concept of "callback" associating this in a realworld context? there is a callback interface in SAX so i would like to get a clear idea of this callback before getting into these interface.
thanks.
himal
 
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the word "callback" refers to the notification mechanism. When we say the following -
xmlReader.setContentHandler()
xmlReader.setErrorHandler(), etc.,
what it means is that we are registering with the xmlReader parser to receive callback(notification) about the events that happen when the parser parses the xml document. I guess this is a brief explanation of what exactly happens.
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
'XML in a nutshell' explains the concept in the following way -

The SAX API is unique among XML APIs because it's an event-based push model rather than a tree-based pull model. As the XML parser reads an XML document, it sends your program information from the document in real time. Each time the parser sees a start tag, an end tag, character data, or a processing instruction, it tells your program. You do not have to wait for the entire document to be read before acting on the data at the beginning of the document. The document is presented to your program one piece at a time from top to bottom. You can either save the pieces you're interested in until the entire document has been read or process the information as soon as you receive it....


You need to look closely at some examples to grasp this beautiful mechanism.
Cheers,
Dan
[ October 09, 2002: Message edited by: Dan Drillich ]
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your alarm clock is a real world callback methods you set. When preset time arrives, it calls you back and wakes you up.
I originally learned callback from c/c++. You pass a (callback) function pointer to the method. When something happens, the function is called.
The same concept is used by Java EventListener, Swing Timer. SAX is another use of it.
In GoF design pattern terminology, it is called Observer/Observable design pattern, or Publisher/Subscriber design pattern.
Happy learning!
 
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In client-server system, callback means that
server calls the client.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic