Comparison
CallbackvsObserver pattern
Callback
you passed a function in and something else decided when to call it, possibly twice, possibly never.
Handing a function to another component to be invoked later, the smallest possible form of inversion of control. It is a one-off observer, a one-function strategy and the primitive under every event API. Its costs are the ones every asynchronous codebase learns: no guarantee about how many times or on which thread it runs, and error handling that does not follow the call stack.
Full entry →Observer pattern
you changed one field and four other things updated, and finding out which four meant reading a subscription list.
A subject holding a list of dependents and notifying each of them when it changes. It is in-process and direct: the subject holds references to its observers, so the two know about each other in a way publish-subscribe deliberately avoids. Its recurring problems are all lifetime problems — observers that are never unsubscribed keep their subject alive, and notification order is an unwritten dependency people come to rely on.
Full entry →