It's not a secret anymore!
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Hard coded constants Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Hard coded constants" Watch "Hard coded constants" New topic

Hard coded constants

Jon Pengelly

Joined: Feb 09, 2004
Posts: 15
Hi all,
I have a helper class (Contractor) that I use in my Data class and my Adapter/Bridge class. It is used to populate my record cache and also holds matching methods for the criteria match and things like that.
However, I have the following constants defined in this class : NUMBER_OF_RECORD_FIELDS, NAME_INDEX, LOCATION_INDEX, etc...
This information is provided in the database file header. Thus, should I be using those values rather than these constants?
The reason that I went for the constants in the first place is because if the data file was changed this contractor class would have to be updated anyway to include the changes (a new field for example), and so the contractor class would need to be updated anyway.
What do people think of this decision? What about the decision to have a helper class in the first place?
Jacques Bosch
Ranch Hand

Joined: Dec 18, 2003
Posts: 319
Probably nicer to have it dynamically read in the real world. But, as you say, then that class would have to be updated anyway if the data changes.
Flexable data structures is probably out of scope for this asignment. Fun though.

Jacques<br />*******<br />MCP, SCJP, SCJD, SCWCD
I agree. Here's the link:
subject: Hard coded constants
It's not a secret anymore!