Comparison
Domain eventvsObserver pattern
Domain event
the model recorded that the order was placed as a thing that happened, and three unrelated reactions followed.
An object naming something significant that has occurred in the domain, in the past tense, carrying what happened rather than what to do next. It decouples the thing that changed from everything that must react, and it is how aggregates coordinate without one reaching into another. Making them part of the model — rather than an integration mechanism bolted on later — is what distinguishes this from simply publishing messages.
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 →