Dynamic Constants

Dynamic Constants

In applications that cannot be recompiled (e.g., apps that are installed on a customer’s machine as binaries only), values of constants may change occasionally. For example, exchange rates and the local sales tax rate are constants whose values are subjected to change. Using compile time constants for such values may cause maintenance problems. Consider:

 const double SALES_TAX =5.0; // not recommended.

Imagine what would happen if the local sales tax was raised or lowered. The user wouldn’t be able to modify the code and recompile the application. A better solution is to use a dynamic constant. A dynamic constant is a variable whose value is read from an external source, say a database table, an environment variable, a file, or a Web page at program’s startup. This value remains fixed until the application exits. Once the application executes again, it will read the updated values of these dynamic constants.


Share the Post: