views:

29

answers:

1

Hello,

I've been thinking for a while on what to store at the Project Settings, objects or numeric/string representations of those objects to set a rule and avoid thinking on this at the future so I want to take the best approach.

On one side storing object representations grants you that what is stored is valid and saves you from doing conversions each time you access them. You only need objects with the attribute.

At the other side storing the numeric/string representation of an object eases the editing of the setting because at the end the user will be entering numeric or string information.

What do you do with this issue?

A: 

Interesting question. Personally, I try not to store complex objects in the settings, because (in my opinion, which is subjective) it makes the code harder to understand for a maintenance programmer. I tend to use the simple types (sting, int, etc) in the settings.

In cases where I have a complex object with a lot of properties, then I may store the property values in the settings file.

For example, let's say you have a custom ErrorLoggingModule that has properties like "DatabaseConnectionString", "ApplicationID". (We use something similar to this and each application we write gets a unique application ID. This gives us a central error logging database for ALL our applications. )

I'd store each of those values in the settings file, and have one routine for logging errors. This routine would create a new ErrorLoggingModule object, read the appropriate settings from the file, and apply the values from the settings file to the appropriate properties, then do whatever I need to do with it.

David Stratton
How about just making the ErrorLoggingModule serializable and write it at the Settings directly?
SoMoS
To me that seems harder for the maintenance developer who comes after me. I could do it that way, but I tend to go the simpler route 90% of the time when presented with two options. (Unless the simpler route hurts security , user experience, or code clarity.) In this case, it's just simpler to use the settings designer and use standard data types.
David Stratton
Yes, but then you need to validate all the values stored there just in case someone edits directly the configuration file for example and that adds more complexity ... maybe you're right anyway ...
SoMoS