I'm creating an application that is composed using different modules (core, course, grades, news). I'm using clean architecture for the different modules but I'm stuck trying to pass data from one module to another module.

The idea is plug into one application (app1) several modules or use them in another application (app2) and has modules very decoupled each other. Modules should depend of core module only and maybe to another module too.

I was thinking in use dependency inversion to receive data. For example grades module need a course object, so, grades module is expecting a course interface. This interface is created in core module (grades and course know it) and course module has the implementation. I want to know if is a good approach? What do you suggest?



No this seems to be a bad way to do dependency inversion (also because it really isn't dependency inversion if you try to do this between apps)

The course module knows what a course looks like. He is the owner of the course data. So it should be able to dictate what the course interface looks like.

Dependency inversion works well with interfaces within a program. However if you are talking to separate apps then i don't see this working well. An app works better if it can be the owner of it's own interface.

Also if apps communicate it's often done on 'real' destinations. Like i do an Http GET https://someapi/courses . That's the actual destination of the app that implements my api, so that too breaks dependency inversion.

If you do want loosly coupling between apps you could consider broadcasting events to an event bus. Then it's up to each app to implement the handlers for any event they might be interested in. But that way they no longer care about who sends a particular event. They also no longer care where exactly the other app (or apps) are hosted and if they are actually online all the time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.