Example by Parable and Analogy
I have a secretary. At the end of the day, I ask her to: (i) take the firm’s outgoing mail and to drop it off at the post office, and in addition to that, after she has dropped the mail off, I ask her to do something else: (ii) whatever task I wrote for her on one of those sticky notes. Now, what is the task on the sticky-note? It depends on the day. Sometimes it might be to: (i) purchase some stationary. Other times it might be to: (i) file some papers, (ii) send some emails, (iii) print some documents etc.
Suppose on this particular day, I require her to print off some documents. In summary, first, she needs to drop off the mail and immediately after that is done, she needs to print off some documents.
Applying the story to some techno-computer geek speak
The method name in this case is: DropOffMail. And the call back function is: PrintOffDocuments. The PrintOffDocuments is the call back function because we want the secretary to do that, only after PrintOffDocuments has run.
So I would “pass: PrintOffDocuments as an “argument” to the DropOffMail method. Now the DropOffMail method must be able to accept functions in its method signature. After the DropOffMail is run, then the call back function, PrintOffDocuments would be called and would run.
So in short, the mail would be delivered, and she would run a print job (which would be the call-back function).
I hope that was simple enough for you!
Leave a Reply