aspose file tools*
The moose likes Beginning Java and the fly likes Multiple sets of constants Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Multiple sets of constants" Watch "Multiple sets of constants" New topic
Author

Multiple sets of constants

Gael Robin
Greenhorn

Joined: Jul 22, 2007
Posts: 5
Hi,

I am looking for the proper solution to the following problem. I am programming an algorithm modeling Lead Acid Batteries with many equations involving more than 25 coefficients which are different according to the technology.

I am looking for a solution which might look like :

- a top abstract class with non abstract methods containing the algorithm
- several classes extending this class to provide the set of constants corresponding to each technology
- moreover I would like the constants to be actually constants

Given the fact that we can't override variables, I am not sure I have found the right pattern to solve this problem.

My temporary solution is :
- abstract class with protected constructor (I am using a public static getInstance method to instantiate an object of the proper subclass)
- the top level abstract class has a constructor expecting an EnumMap in which all the parameters can be recovered to initialize private final instance variables.
- a class for each technology extending the top abstract class with a private static final EnumMap initialized with a static initializer.

Thanks in advance for your answers.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31079
    
163

Gael,
Welcome to JavaRanch!

Why not provide getter methods that reference the true constants? Then you can get the benefits of OO without losing the real constants you were looking for.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiple sets of constants