I'm looking to make a clean modular architecture. I hear all around how bad are circular dependencies, and I'm convinced that the less two modules are coupled, the most reusable the code will be.
But I want to handle edge cases where moduleA depends on moduleB and vice-versa.
Generally speaking, an architecture like this doesn't sound bad to me (very simplified):
All modules "register" themselves at startup into the bridge service. A module can have different interaction with all other modules:
- ẁe can do
bridgeService.hasModule('moduleName')
to create "weak" dependencies - we can call a function of a module like
bridgeService.moduleName.myFunction()
- the bridge service can handle errors and virtualize the dependencies map of the application
- It may happen that moduleA calls moduleB and moduleB => moduleA but it wont be a circular dependency except if functionA calls functionB and in return fnB calls fnA. In that particular case, javascript throw an explicit
stack size exceed
which is easy to fix.
I have a minimalist example that work well and I like the way it handles modularity.
The problem is I never found an example of such an architecture in literature, that's why I'm not so confident even if everything looks fine to me.
Is it a bad design ? What are the drawbacks or the positive about such a design ?
Thanks for your answers
NOTE: I'm working with nodeJs, thus I don't have to deal with compilation issues.