tags:

views:

121

answers:

3

Hi,

Quite simply, it of course makes good sense to group parts of an application into appropriate modules.

Commonly, keeping these modules decoupled is not an issue, however it often arrises that data from the a user management module is required by other components.

It is substantially less than ideal by normal principles that these client modules would have knowledge of the user module's internal classes etc, which brings me to the question of how this cross-module communication is best architected.

My thoughts thus far are that a module could have a conventionally-named API class via which other modules could 'query' the module. This approach will still lead to a certain dependency, but at least only on the other module/its API.

Your thoughts on this would be greatly welcomed.

Thanks in advance, James

A: 

Well, "module" is extremely vague - exactly what defines a module can vary greatly from system to system.

I'm actually confused by exactly what type of scenario you're trying to avoid. It's not uncommon at all for two classes or groups of classes to communicate with eachother. That's why we have stuff like interfaces in the first place.

I guess in your scenario you could have a controller-like class (as in the C from MVC) in between your modules that would know the guts of each and could serve as a communication bridge.

Peter Bailey
Sorry for the ambiguity!This is actually with respect a simple implementation of the MVC pattern, and a module encapsulates (by means of a physical directory) its necessary MV and C components.My question in its rawest form then is essentially how a controller in module X might communicate with a model in module Y?
jstephenson
In that scenario, I would make the model in X load the model from Y on its own. The controller doesn't need to manage that communication.
Peter Bailey
And in terms of keeping modules decoupled with each other, Summer's suggestion above would seem sensible to me. I think a combination of these both would work well. Would you tend to agree?
jstephenson
+1  A: 

You could call the user module a "library". This terminology change can help clarify which modules are supposed to be top-level, and which ones manage lower-level activities that are intended to be used by multiple other modules. The CodeIgniter PHP framework uses this approach.

Summer
A: 

You might want to read up on "dependency injection". Symfony Components offers a solution for Dependency Injection and has lots of good reading/examples on the subject.

Thanks for your input. I had briefly considered some DI container based solution, though to do this properly it would require that the data-mapper controller X depended on conformed to some type-hintable interface, and there is then the question of where this interface should live within the application/module ecosystem (hopefully that makes sense...)?
jstephenson