What's the best way to store app settings? (MVC)

I am developing a swing application that follows the MVC pattern and I am wondering what is the best way to store settings like width / height, location of xml files ... Should these settings only be accessible through the model? Should I be using a global static class? Single element?

Thanks in advance

+1


a source to share


3 answers


I suggest .java.util.prefs

.

Preferences



Then you don't need to invent anything.

+6


a source


I've actually used the Swing Application Framework in NetBeans with a lot of success here doing it in a way that you don't have to worry a lot about design patterns either :)

Before that, I used to save window properties in properties files and I had a separate model / configuration service that I injected where needed to retrieve properties when re-creating windows.



I don't understand why it should be Singleton. Probably an anti-pattern in this case.

0


a source


It depends on the settings you are talking about.

Width

and Height

sound like properties that only apply to the View portion of your project, and therefore should be stored there. Xml file location

sounds more like a model problem.

When developing in Java (which I quite rarely do ...) I try to create a named class Settings

in which I store everything I need as private fields, using getters and / or setters where necessary. In an MVC template, I will have one settings class in each section and (if necessary, but not one) one "global" settings class. But if you're interested in following the sample, make sure each setting is only available where needed.

0


a source







All Articles