• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Should I hard code field names?

 
Garry Kalra
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the GUI, i am providing with the to and from fields,
should i hard code the name of these fields for performing
the search.
Gaurav
 
Shailendra Guggali
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you should get it from the Database each time - so that itbecomes independent of the database, i.e., any additions to the database will automatically reflect in your search.
Its quite straightforward - get the record - get value - in array - get the appropriate index value - put in a collection to eliminate duplicates - add 'any' to the list and pass it to a combo box constructor
 
James Nuzzi
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I hard coded the values for my to and from combo boxes and I still got a perfect score on the GUI section.
I agree that this is not the best way to do this. If any new airport codes are added the GUI will have to be modified. However, if you perform a lookup to read every record from the database and get this list you could have performance problems. Specifically, if the database becomes very large and there are still only a few unique airport codes a lot of time will be wasted reading in duplicate codes.
Just something to think about.
------------------

James Nuzzi
SCJP, SCJD, SCWCD
 
Rick Fortier
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think your question is really, "Should I hard code the names of the database fieldnames in the gui".
The answer would be that you should put the column names in a constant somewhere. They have to be hard coded somewhere.
Of course if your question is "Should I hard code the cities that can be selected", then the answer is no. The way I did it was on startup to get all list of all of the city names using a TreeSet class. Then you could also provide a way for the user to refresh this list from a menu.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic