I want to design an event generating/consuming for a system, There would be various types of event occurrences in various situations. What I found is I need to write the event generating code everywhere and the event generating code is tightly coupled with the business logic.
For example, for an event of object change, I wrote some code in all the methods that changes that object, and the methods that change the object spread in many place in project.
As another example, for each object, there is a changed event for which I have to write event generating code for all objects.
I believe you guys have some experience in solving the problems, and implement a loosely-coupled and easy-to-maintain system. Do you have any suggestion?
My implementation language is Java, but I think this problem is valid for any language, if any Java specific solution is also welcome :)
Thank you!
You might want to have a look at google guava's EventBus mechanism. It's a nice and easy way to decouple much of the event handler registering boilerplate from your objects.
And if you want to see it language agnostic, event bus is just a pattern describing a publish/subscribe event dispatching mechanism.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With