title: In Java can you use getter and setters in a parameterized manner i.e pass in a code to decide which class variable to return
body: <p>I'm working on a project that requires me to have three specific ticket types that have certain properties.</p>
  
  <p>Some of these properties are final and static as they should not change, however further types could be required. This would mean changes to the abstract class but not the class implementing it. I have created an abstract class that contains these class variables in order to limit the logic I need to write in the class implements the values. I have written getter methods that receive a parameter (a ticket type code) and then the method switches the code and returns the appropriate value. In the setter methods I receive a code parameter and then update the class variable dependent on the code received.</p>
  
  <p>My questions are: </p>
  
  <p>1.Is this bad practice if so should I revise the design of my class? 
   2. And if so, how should I approach the problem in a way that I could make the code reusable and parameter driven?</p>
  
  <p>Previously I would have created an xml or parameter file so I could change the parameter file instead of making code changes but I have not coded in Java for a few years and I am still learning the best practices.</p>
  
  <p>Here is a code snippet:</p>
  
  <pre><code>private static final int iPickThreeLimit = 50;
  private static final int iPickFourLimit = 40;
  private static final int iPickFiveLimit = 60;
  
  private static int iPickThreeCount = 50;
  private static int iPickFourCount = 40;
  private static int iPickFiveCount = 60;
  
  protected static void setTicketCount(String sTicketType) {
  
      switch (sTicketType) {
      case "PickThree":
          AbstractLotteryMachine.iPickThreeCount = iPickThreeCount--;
          break;
      case "PickFour":
          AbstractLotteryMachine.iPickFourCount = iPickFourCount--;
          break;
      case "PickFive":
          AbstractLotteryMachine.iPickFiveCount = iPickFiveCount--;
          break;
      } //end switch
  } // end setTicketCount
  
  protected static int getPickLimit(String sTicketType) {
      int iTicketLimit = 0;
  
      switch (sTicketType) {
      case "PickThree":
          iTicketLimit = iPickThreeLimit;
          break;
      case "PickFour":
          iTicketLimit = iPickFourLimit;
          break;
      case "PickFive":
          iTicketLimit = iPickFiveLimit;
          break;
      } //end switch
      return iTicketLimit;
  
    } //end getPickLimit
  </code></pre>
  
  <p>If I have to write an individual getter and setter method for each ticket type this balloons the logic required in the class I am implementing this abstract class in.</p>