Should I create an Enum mapping to my database table
Posted
by
CrazyHorse
on Programmers
See other posts from Programmers
or by CrazyHorse
Published on 2012-09-27T12:56:00Z
Indexed on
2012/09/27
15:50 UTC
Read the original article
Hit count: 197
object-oriented
I have a database table containing a list of systems relevant to the tool I am building, mostly in-house applications, or third-party systems we receive data from. This table is added to infrequently, approx every 2 months.
One of these systems is Windows itself, which is where we store our users' LANs, and I now need to explicitly reference the ID relating to Windows to query for user name, team etc. I know it would be bad practice to embed the ID itself into the code, so my question is what would be the best way to avoid this? I'm assuming my options are:
- create a global constant representing this ID
- create a global enum containing all systems now
- create a global enum and add systems to it as & when they are required in the code
- retrieve the ID from the database based on system name
I appreciate this may seem a trivial question, but I am going to have many situations like this during the course of this build, and although we are in complete control of the database I would like to conform to best practice as far as possible.
Many thanks!
© Programmers or respective owner