Reputation: 72514
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?
Upvotes: 2
Views: 91
Reputation: 328614
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.
Upvotes: 1
Reputation: 61526
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).
Upvotes: 2