I was recently asked what is the difference between a callback and an observer in the Observer OO design pattern. My understanding is that callback is any executable code passed as an argument to a function which is called when a specific event happens. It may be implemented in different forms in different programming languages, such as function pointers, anonymous functions and observers/listeners in the object-oriented paradigm. Developers usually implement callback registration synchronously with code execution and support only one callback, while observers/listeners callback registration is always asynchronous with code execution and multiple registration is supported. However, I believe that those usual limitations of sync and cardinality in a callback are not inherent in its definition. Is that right?
Reference: https://en.wikipedia.org/wiki/Callback_(computer_programming)
Aucun commentaire:
Enregistrer un commentaire