tags:

views:

128

answers:

2

How do you manage symbolic constants in your projects? Where do you declare solution scope constants ?

+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
`public static const` or `public static readonly`, I hope.
tvanfosson
yeah, I should have put that in too.
Kevin
+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
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
@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
@Marc - I assume that these are cached in some global dictionary or do you retrieve them from persistence medium each time?
tvanfosson