Thanks norm... from my blog...
So I've been working on air density equations that use the dry air constant.
Since I'm working with Java I set this up simply like this...
Quite beautiful and simple, right? No, wrong!
Since the constant is made up of gases... the overall 'constant' can be different based on location. I discovered this eventually by trying to figure out why different air density calculators were giving different results. For example:
Dry Air Gas Constant of 286.9 from The Engineering Toolbox
Dry Air Gas Constant of 287.22 from Peace Software
Dry Air Gas Constant of 287.05 from Brisbane Hot Air Ballooning
Dry Air Gas Constant of 287.058 from Wikipedia
So with all this being said, how do I implement my code?!? I gander there are a few options...
Constant/non-constant Option 1
OPTION: I could just create constants for each known location...
PROBLEM: However, I don't think this would work as it may not be practical to keep doing coding changes for locations, and what if the values at those locations change? (you can't dynamically change a final constant).
Constant/non-constant Option 2
OPTION: I could set the code up with getters/setters to allow for the changing of the 'constant' :
PROBLEM: The desire is to have the utility available as a Java utility class, and getters/setters do not support this model.
Constant/non-constant Option 3
OPTION: perhaps I could enumerate the constants, and associate the values after the fact.
PROBLEM: The code would still be subject to adding and modifying regional values.
Constant/non-constant Option 4
OPTION: I could utilize a web service that queries the dry air gas constant via location.
PROBLEM: This seems to be the best approach, but such a thing does not exist
Constant/non-constant Option 5
OPTION: Since all the constants are very close in value... only provide one and let the user deal with difference in results from there desired value of which they cannot set.
PROBLEM: The result would not be accurate/precise.
Constant/non-constant Option 6
OPTION: Allow the user to pass into the methods as an argument, the desired constant value.
PROBLEM: Uh yeah, why would someone pass a 'constant' into a method?!? Well, if you followed the post, this is apparently thee time you'd want to... and probably what makes the most sense.
Do you have other suggestions? I posted this question to CodeRanch... let's see what those guys and gals have to say.