views:

270

answers:

3

Hi

I'm developing a swing app which suits the MVC pattern and I'm wondering about the best place to store settings such as width/height, xml files location... Should those settings be avaiable also only through the Model? Should I use a global static class? A singleton?

Thanks in advance

A: 

I actually used the Swing Application Framework in NetBeans with great success here which deals with it in a way where you dont have to worry too much about design patterns :)

Before than I'd normally store the window properties in properties files and I had a separate config model/service that I injected where it was needed to retrieve the properties when re-creating windows.

I cannot see why it would need to be a Singleton. Probably an anti-pattern in this case.

willcodejavaforfood
+6  A: 

I'd suggest java.util.prefs.Preferences.

Then you don't have to invent anything.

John Gardner
A: 

It depends on what settings you're talking about.

Width and Height sounds like properties that are only relevant to the View part of your project, and should thus be stored within it. Xml file location sounds more like a Model concern.

When developing in Java (which I quite rarely do...) I tend to set up a class named Settings in which I store whatever I need as private fields, with getters and/or setters where it's needed. In an MVC pattern, I'd have one settings class in each section, and (if necessary, but rather not) one "global" settings class. But if you're concerned with pattern conformity, make sure that each setting is only available where it's needed.

Tomas Lycken