0

We have a project that has several war files that reference one-another. I've recently realized that there is a circular-dependency between two, in particular, the utils and the models. Other services use both of these, and the utils was created for operations that would be performed on the models by other services. I was just curious what is best-practice here. Utils and models sound like they are companions to the main project, but I've never heard of a war file being called 'utils and models'... just seems strange.

Additional Info (not necessarily needed to answer the question): To be more specific, the model uses the utils for it's type adapters, which allows MyBatis to convert timestamps to joda time. The utils uses the models, which I think is more acceptable, to do common operations on model objects.

Should I just combine both into the models war? What are some other options I would have. If I should combine them, is there some sort of design pattern that combines utilities and models together? What's the appropriate naming convention for a service that supplies both model and utility classes?

Matt
  • 5,408
  • 14
  • 52
  • 79
  • Combine if they always make sense together, or split out the parts needed by both into a separate project and have each depend on that. This may be a duplicate of what you're asking: http://stackoverflow.com/questions/16468525/how-to-resolve-maven-cyclic-dependency – Marc Baumbach Sep 01 '15 at 02:34

2 Answers2

0

There are a lots of post on how you can remove cyclic dependencies like maven cyclic dependencies
But regarding utils a general advice is that utilities can be of two types in the sense that they are general or project specific i.e. if you are writing general utilities then those should not depend on any of your modules(they just perform general tasks) so should always come first in your reactor build order.
Secondly, for project specific utilities you can always do 'xxx.modals.utils' as in your scenario and these can easily consume your beans.

One more reason that general utilities(independent of your beans) should be kept in a different module is that they can be easily reused in other projects too. Hence you don't have to reinvent the wheel time and again!

Community
  • 1
  • 1
Shubham Chaurasia
  • 2,472
  • 2
  • 15
  • 22
0

I believe that the solution to your question would based on the view and experience and not a technical problem as such. I would suggest the following:

  • Go with Utils in same module if : Your Model classes' are not going to be reusable in other modules. In other words, if your Util classes is in relationship with Model classes only. It wouldn't make sense to split it as a module if your util classes are just designed for the specific model classes only.

  • Go with Utils in different module if : Your util classes are going to be generic. For example, your Utils classes are designed to convert the Model/Entity to Business Objects using some DataMapper like Dojo/Orika etc. That's coz, these util classes would not be tightly coupled to the Model classes as they would have the implementation to convert any type of Model to Business/Value Objects and vise versa.

This is actually been addressed by micro-services where you concentrate on loosely coupling the services which can survive independent of each other(like a plugin component).

Karthik R
  • 5,523
  • 2
  • 18
  • 30