Domain events

A domain event is a domain object that defines an event.

Domain events are powerful mechanisms to keep domain models encapsulated. This can be accomplished by allowing various observers from outer layers to register for a domain event (signal).

The problem with domain events in OOP is that the typical implementation is complex and relies on side-effects. Event observations are typically declared in the composition root and thus, it is not immediately obvious from the perspective of the producer which observers will be invoked. In FP, a domain event is simply a value returned by a function in an aggregate. Observers can be explicitly registered as filters.

Furthermore, FRP can handle domain events very effectively. On the other hand, returning domain events from aggregate methods in OOP is prohibitive due to the lack of union types and pattern matching.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset