title: Using enums and switch statements to control method execution
body: <p>My question concerns a specific design convention for methods in Java... but really it would apply to C++, C# and others as well.  I don't know what this convention is called, but if there is a standardized convention, I would like to know how to find it.  In other words, I wish to describe this convention as I have encountered it and be directed to a place where I can learn more.  </p>
  
  <p>Consider java.util.Calendar, specificlaly its child, GregorianCalendar.  It has an interesting "getter / setter" convention.  Let's say that you instantiate this object:</p>
  
  <pre><code>GregorianCalendar cal = new GregorianCalendar();
  </code></pre>
  
  <p>The fields of cal now describe the instant in time (down to the millisecond) at which the constructor was called.</p>
  
  <p>Now let's say that you want to access the year field or the month field.  You would use the following getters.</p>
  
  <pre><code>int year = cal.get(Calendar.YEAR);
  
  int month = cal.get(Calendar.MONTH);
  </code></pre>
  
  <p>Notice that it's not cal.getYear() or cal.getMonth().  It looks like there is only one getter method for this class and that the return value is determined by the parameter naming the desired field.  I would imagine that within the class there is an enum set up to list the fields... and that the getter function itself is composed of some kind of switch statement.</p>
  
  <p>This type of architecture is not described in any of my books... it is however something that I've been using in my current work... but I've been doing it "my" way (basically just making it up as I go along).  If there is a standardized way of doing this that other people use... I'd sure love to know it.  Specifically, using enums and switch statements to control the execution of methods.</p>
  
  <p>Thanks so much for your time!  This is my first question on this site... I have been a long time lurker though.  :)</p>