How do you manage symbolic constants in your projects? Where do you declare solution scope constants ?
views:
128answers:
2
+3
A:
We have a constants class where we put all the constants in. We declare it static and then make the constants static public, since there is no need to instantiate it.
Kevin
2010-04-29 11:45:11
`public static const` or `public static readonly`, I hope.
tvanfosson
2010-04-29 11:49:30
yeah, I should have put that in too.
Kevin
2010-04-29 11:51:18
+3
A:
It is pretty rare (for me at least) that there isn't an obvious relationship between such constants and some pre-existing class at the heart of the domain model - I'd just add them there. Then the constants are tightly scoped to the appropriate part of the model, rather than just being in a "Constants" class.
Of course, I also find it pretty rare to find true "constants"; many interesting "constants" are described better through configuration options.
Marc Gravell
2010-04-29 11:46:33
Exactly my thoughts. Constants, if I have them, are typically only meaningful -- or at least most meaningfully used within a class. Globally used values are almost always configuration items, i.e., they're constant once set, but are best defined in a configuration file.
tvanfosson
2010-04-29 11:52:33
@tvanfosson - I've also found on more than one occasion that even my "global options" soon become injection options, with different use-cases using different global options. Multi-tenancy being the most obvious example.
Marc Gravell
2010-04-29 11:56:06
@Marc - I assume that these are cached in some global dictionary or do you retrieve them from persistence medium each time?
tvanfosson
2010-04-29 12:01:12