Reputation: 1340
I have dialog for storing user preferences of the application which is developed using Java Swing. There are 20+ preferences and I would like to notify other modules when the particular preference changes. I know that I can hold a list of listeners and notify them whenever the preferences change. However, I would like to know about two issues:
Dependending your experience, how would you resolve that architecture? What are the best practices to follow?
Thanks
Upvotes: 0
Views: 258
Reputation: 2221
I developed a Swing application where the user could modify some parameters to change functionality or the graphic of the application.
I approached it this way:
Setting
abstract class represent a single value that the user can change.Setting
and a Preferences
object to store the values.For the actual settings, I create a static attribute somewhere (in my case, dedicated classes for different logical groups of settings) and use that attribute to read and change the values fo the settings.
PRO: The Settings
keeps track of all the settings instantiated, so I don't need to code the frame for changing them twice, I just did it once in an indipendent way from the number of the settings
CONS: It clearly requires changing the code to add a new setting. While in my case it was not an issue because a new setting was needed only because of other changes in the code, in your case it might be.
Upvotes: 1