• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Where to store constants?

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I really doubt where to store the constants according to a good programming design.

Situation
----------
Here is my situation. i have an email address and my application has an email functionality to send out the email using this email address.

Right now, this email address is used in only one place.

1. Can i store this email address in the code file where i am using?
2. Can i have one common code file to have all the constants used by the application?
3. Can i have a table called 'key_values' table which will store values in an array list format
eg: Key Value
-------------------------------
email_addr myname@mycomp.com
sender_role admin,user,guest

please let me know which option would be good.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While the three options you mention are all possibilities, for configuration options that rarely (if ever) change -like email addresses- I'd use a properties file, and make its contents available to all classes of an application. That could happen either through a static method in some class, or through a config object that each class has access to.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This forum is for "operating systems, applications, hardware, drivers, features, etc. General computer use stuff." I'm going to move it to one of our coding forums for you.
 
So it takes a day for light to pass through this glass? So this was yesterday's tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic