Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code Practice question

Status
Not open for further replies.

abcfantasy

Programmer
Jun 3, 2006
110
DK
Say there is an xml file (or maybe other kinds of file) that contain general settings about your application (can be anything: text/integers/etc...).

Now, you have a method which gets the settings from the file and returns them as one object, what should the object be? Assume that the types of the settings vary.

1. Should it be a kind of array that holds objects? In this case, you need to hardcode a lot of things. For each setting, you will have to specify in which place the setting is in the array, and type cast it to the correct type. So if any of these two changes, you would need to change more code. Also, would it be better to use ArrayList or simply object[]?

2. Should it be a whole new class simply to store the settings in seperate fields?

3. Perhaps any other option?

I've encountered this several times. The first seems the easiest, shortest and quickest to do but somehow there's a "dirty" feeling in doing that. The second seems good, but feels like too much work involved for a simple thing.

So I was wondering what is considered to be "good practice" to tackle such a situation.

Thanks in advance.

|| ABC
 
Use app.config and the System.Configuration.ConfigurationManager classes that already exist?
 
Using app.config is one option, if the settings are only read by the program, and never written.

WRT using a strongly-typed class to represent the configuration data (vs. an array of object, or something else), a lot depends on your intended use, and how often it'll get used in the program, and whether the program is expected to have a long life, and so forth.

If the program is expected to be maintained for years, or if the config values are frequently accessed withing the program, then I would go for the strongly-typed class.

If the program is a one-off, or the values only get used in one small spot within the program, I'd lean towards weak-typing.

Chip H.


____________________________________________________________________
www.chipholland.com
 
Yes, settings are read and written.

Thanks, chiph, that answers my question.

|| ABC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top