title: Dozens of getter methods vs a single get method
body: <p>I got into a discussion with a colleague regarding the following issue:</p>
  
  <p>Our project reads in a config file and stores dozens of parameters. He's stored this data in named variables together with dozens of getter methods for each variable. In my opinion, this has made the class overly long with getter methods and difficult to maintain.</p>
  
  <pre><code>private var;
  
  public String getVar() {
   return var;
  }
  // This appears dozens of times in the class
  ......
  </code></pre>
  
  <p>My solution is to store key values pairs in a map, and have a single getValue(String key) method which takes as argument a key which represents each variable. The keys will be stored as a list of constants in a Config class which will also handle reading the data from file.</p>
  
  <pre><code>Config c = new Config();
  c.readConfig(someFile);
  ...
  c.getValue(Config.SOME_VAR);
  </code></pre>
  
  <p>His argument against my design is that if any key needs to change or be made obsolete, all instances of the key will have to be hunted down and changed at many places in the source code, whereas in his design everything is managed from 1 file. Also, type safety poses a problem, as Integer.parseInt() from a String returned from getValue() might crash, whereas in his method, the return type is fixed.</p>
  
  <p>Any comments regarding the above? Thanks.</p>