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 the have different interaction with all other modulesA module can have different interaction with all other modules:
- itẁe can call bridgeService.hasModule('name')do
bridgeService.hasModule('moduleName')to create "weak" dependencies - itwe can call a function of thata module like bridgeService.moduleName.function()
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 exceedwhich is easy to fix.
I have a minimalist example that work well and I like the way it handles modularity. Altough I know we shall avoid at maximum inter-module dependencies, this seems to solve the
The problem. But 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.
That's why I need your lights. 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.
