views:

88

answers:

2

URL generation in my web app is in charge of the presentation layer. Now consider another module sending out messages containing URLs. (Not neccessarily triggered from presentation). However, the presentation layer has to know about the module (since it might be the trigger, and the user can configure the module using the frontend).

I.e. the modules are dependent of each other... any ideas how this cyclic dependency could be avoided?

Storing URLs in my database does not seem right to me, same goes for merging the two modules.

Any help or inspiration is be very much appreciated. Thx.

A: 

Create a third module which both modules know, but they don't know each other?

Thorbjørn Ravn Andersen
hmmm maybe I just don't get what you are pointing out, but...if A depends on B and vice versa, and we're plugging C inbetween,we've got two cyclic references: A<->C<->BIf you are suggesting to enclose URL generation in a thirdproject: I do not think this is possible... the page classes are needed for url mounting, the URLs are needed to generate links on the pages....
peter p
No, make A->C and a B->C dependencies.
Thorbjørn Ravn Andersen
A: 

Wouldn't using an interface help here? How about specifying and "consuming" an UrlGenerator interface in your backend module and implementing it in your presentation layer?

In combination with some sort of dependency injection mechanism (Factory pattern for construction of UrlGenerator clients, frameworks like Spring or Guice, Service Locator pattern), this will break the cyclic compile-time dependencies.

springify