tags:

views:

44

answers:

2

I have a small Java application which uses some configuration settings, which are saved between sessions.

I started to create a Configuration class which provides the settings and can save and load itself to a Properties object.

But because it's a very small application with few settings I asked myself, if I just could use a Properties object directly. ("Just one more layer and the problem goes away" :) )

Is this good or bad practice?

+2  A: 

Well you could use Properties or you could use the java.util.Preferences. My preference (no pun intended) would be to abstract the two - or write a PropertyPreferencesAdapter and use Preferences as the API. That way if you want to switch later it'll be much easier.

You could also use something like JDNI to find the settings later (I doubt it given what you said) and in that case I would probably abstract further.

This article discusses the topic somewhat (not exactly what you are asking, but not bad info).

TofuBeer
+1  A: 

You should have a look at the Properties class again. Unnoticed by a lot of Java developers, this class learned to use XML a few years ago which makes them much more stable, easy to use and reliable.

Aaron Digulla
Because XML is like violence: If it doesn't solve your problem, you're clearly not using enough of it.
gustafc
I'm not a huge fan of XML or violence but that doesn't mean they don't have their place. In the XML case, it's very well suited for external config files. This comment box doesn't have enough space to explain the other case :)
Aaron Digulla