Skip to main content
added 238 characters in body
Source Link
TOPKAT
  • 131
  • 5

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):

enter image description here

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 exceed which 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.

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):

enter image description here

All modules "register" themselves at startup into the bridge service. A module can the have different interaction with all other modules:

  • it can call bridgeService.hasModule('name') to create "weak" dependencies
  • it can call a function of that module like bridgeService.moduleName.function()
  • the bridge service can handle errors and virtualize the dependencies map of the application

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 problem. But I never found an example of such an architecture.

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.

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):

enter image description here

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.

Source Link
TOPKAT
  • 131
  • 5

Modular programming: module inter-dependency

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):

enter image description here

All modules "register" themselves at startup into the bridge service. A module can the have different interaction with all other modules:

  • it can call bridgeService.hasModule('name') to create "weak" dependencies
  • it can call a function of that module like bridgeService.moduleName.function()
  • the bridge service can handle errors and virtualize the dependencies map of the application

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 problem. But I never found an example of such an architecture.

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.