I have a Java package which purpose is to receive configuration parameters from an external config file (XML, JSON, CSV, etc.), convert them into a POJO and return it in a form of an immutable, extensible object to the caller. Caller may only read parameters, but not modify them. If loading, parsing or conversion fail, the package must return a default configuration object with basic number of settings and predefined values. In the future the number of settings might increase and there might be another data source.
Basically, it's a black box with input and output. Input can be any data source, with basic settings, that can potentially increase. Output is a Java object, which contains all settings (that, again, can potentially increase). And it must be read-only. First, I thought about writing an interface with getters for basic settings, which can be extended if the settings list expands? Something like
interface Config { ... }
abstract class BasicConfig implements Config {...}
class ExtendedConfig extends BasicConfig {...}
Then I thought that maybe parsing XML into a HashMap will solve the problem should the settings list increase in the future. In this case I can make HashMap<String, Object>
and read anything from it without knowing how many settings it contains.
What would be the best design solution here?
Aucun commentaire:
Enregistrer un commentaire