Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

When Good Annotations Go Bad

DZone's Guide to

When Good Annotations Go Bad

· Java Zone
Free Resource

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

At one time not too long ago, I wasn't a big fan of annotations. But then I let my guard down and even started liking them. But now I'm starting to wonder if my dislike was a good thing.

Let's say that I have a class called Document. And let's say that a Document can be indexed into a searchable index using a IndexService class. And let's say that I have a Spring MVC controller class called SearchController that uses IndexService to search for Documents given some search criteria.

Now, just for fun, let's say that IndexService uses Compass to persist Documents to Lucene. And, as for Document, let's say that I chose to use Compass annotations such as @Searchable instead of the Compass' XML mapping.

One final bit of stage-setting: Each of these classes is in a separate project (a separate Maven module). Document is in a "domain" module, IndexService is in an "index" module, and SearchController is in a "web" module.

Okay, so SearchController has a dependency on both IndexService and Document. That's fine, because it will be dealing with both of those directly.

But, as luck would have it, SearchController also transitively depends on @Searchable and any other Compass annotations I use in Document. That means that I can't compile the web module without it having Compass in its build classpath (that is, as a dependency in its POM. Even though SearchController doesn't know about or need to know about Compass!!!

Doesn't this violate the law of demeter?

Someone please tell me that I'm wrong and show me the error in my ways. I want to be wrong here. But I can't seem to be able to build my web module without adding Compass to the list of dependencies...and that seems to be just plain wrong to me.

From http://www.jroller.com/habuma

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}