This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.