The only thing with that is if you might need to change those constants while 
the application is running, you won't be able to this way.  Of course, you 
could argue they aren't constants then, and i'd tend to agree! :)

For instance, in one application I wrote, I read in an application 
configuration file at startup, and store it all in a class with nothing but 
static members.  However, some of the config values can be switched during the 
lifetime of the system.  For instance, this application makes calls to another 
server as a proxy to a mainframe system.  Sometimes we have to take that proxy 
server down, so we just point the application to another temporary one in 
real-time.  No downing anything, it's instant.  So, I can't have that 
information being static.

In such a case, what Eddie says is still valid with regard to the static 
initializer, but now there's a tad bit more work: don't make the data members 
final, just make them private and expose them with getters, no setters, and 
expose a static readConfig() method (which is what gets called in the static 
initializer too).  Then, if you need to change values, just modify the config 
file and have an administration function that calls readConfig().  Best of both 
worlds I figure :)

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com

On Fri, January 28, 2005 10:31 am, Eddie Bush said:
> I'll probably get called insane ... :-)
> 
> Generally, when I have a class that contains constants, I do make them
> final, but I set their value in a static initializer.  Inside of this
> static initializer, I will load the values from a properties file and
> then assign them.  This way, my values are easily changed, if need be,
> cannot be set after initialization, and my class has no dependency
> upon any other class knowning about how to initialize it.
> 
> ... then, I poke tons of stuff into properties files and XML files and
> load them in static initializers.  ... it just seems like a really
> easy way to add flexibility.
> 
> Good Luck!
> 
> --
> Eddie Bush
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to