Java N Coffee

Monday, June 01, 2009

The fickle properties file.

This is one area where serious thinking needs to be done. I have seen lot of people cringe over this but yet they keep going on. Biggest problem I find in a property file is APP VERSION and APP CONSTANTS.

Your mate comes gives you a version and you start out code, after few months you have a small functionality to develop and you have to use the same constants. Then few months down the line you have another HOT NEWS, part of the code you have to add into some other part of code and that new code too has got a VERSION. Only thing you can do is bang your head to a wall.

Another annoying thing people do, property.getProperty(AppConstants.SOME_VALUE) lying all around the code. Then they complain if a constant changes due to TYPO or wrong constant name selection, compile the whole thing and build again as compiler puts the String constants all over the place.

Peace!!!!!!!!

To limit the causality of my brain cells, I got close to , make a single (may be singleton, yes yes I said singleton dont frown on me) class file with getters to all properties right there with string constants encapsulated well in that class itself. So if i need a property from properties file, I'll rather say

AppProperties.instance.getRepositoryLocation()

with all the property file stuff encapsulated in that AppProperties class.

One thing I cringe for is AppVersion, all the time we talk about reuse, seniors spend most of time dealing with it in the end what we have is AppVersion, at the max we could have ComponentVersion.

Labels: ,

Annotation Vs. Xml

People talk about putting meta information about a POJO through annotations, but it makes me wonder, how closely related my meta information should be?

Taking dip into Servlet 3.0 specification, annotations here seems to add value to Servlet classes because as responsibility of a servlet class is to process request and send response, it is also close to server end. Many things I'll write in a servlet will be close to container. Even if I write it in annotations or external XML files, I am not concerned about polluting my class with annotation that I'll have to carry everywhere I move my classes.

Now, in hibernate or JPA for instance, my POJO gets polluted with all the meta information that well suits in an external XML file. It keeps my POJO's clean from annotations. If I have to use a portion of the designed model somewhere else, I not bothered what goes in annotatons, its clean and meta information is externalized.

Percenatage of me reusing a servlet code to a domain object is more and makes life easier to keep POJO devoid of all meta information that can cause problem in future.

This is my view, it keeps things cleaner for me to work with and the usuall rant, makes unit testing easy without carrying framewrok burden.

To conclude there should be balance between how much annotation to use when and where.

Labels: , ,