bevy-design-patterns
bevy-design-patterns copied to clipboard
Event Bridge Pattern
This is about a pattern to make plugins (even internal ones) independent of other code, even in terms of imports.
https://github.com/Pfeil/bevy-design-patterns/tree/generic-events/patterns/event_bridge
Let's shortly define some properties / levels of independence of a plugin:
- the initialization (add_plugins) can be omitted, and your code will still work without any other adjustments like removing imports.
- the plugin can be fully removed, and your code will still work without any other adjustments like removing imports.
I was aiming for both properties. So far, it at least works in the example case. Not sure how it applies in practice. This is a really early idea.
Things which came to my mind, but I was not able to try yet:
- can it be applied to more than events? Like components or other types one would need to import?
- is a configuration resource an alternative, and in which cases?
- can we make a wrapper module which packs the boilerplate and the plugin module in order to further structure the imports in a hierarchical, useful way? (probably yes)
- I believe this is already useful if either the sender or the emitter implement the pattern, at least in one way. I did not try yet, though. We could add some examples, e.g., by using a src/bin folder.
- We have a clone in there, we can probably avoid it somehow.
- I'd like to test / see it in some greater context to see how it works in practice.