Wondering how other people have solved this issue. Let's take the Item/Bid example from the HIA book.
Let's say we want to add a new feature to the system:
1. bidders are automatically notified when the item description is updated.
2. bidders can automatically withdraw their bid when the description is updated.
One way to solve this is to use the Interceptor to listen for updates on Bid. In the callback, we retrieve the collection of items bid for by the bidder and delete the item from that collection. However, this potentially involves lazy loading of collections which is forbidden in the Interceptor callback.
Likewise, one can foresee more and more features that depend on monitoring changes to an item (fraud detection feature, statistics...)
I believe that most domain models will have a few very "busy" objects which everyone (and more) want to monitor for updates / deletions/creations. But the Interceptor callback severely constrains what can be done. Likewise, I think the Event callback is similarly unsuited.
I can think of a couple of solutions:
1. Use the Interceptor callback to queue up change notifications to listeners in a separate thread (fire and forget). this way the callback is only doing one thing and doing it well
2. Build a separate publish / subscribe framework which the service layer must publish to before C/U/D on Item. this is error-prone because people will just forget to do this
3. Anything else?
|