title: Static factory method for sub-classes with variable number of constructor arguments
body: <p>This is more of a style question, where I'm unsure what solution to my problem would be the "cleanest".</p>
  
  <p>The implementation details are not important, what I want to do is the following:</p>
  
  <p>I've got an abstract class that is extended by several subclasses which are all very similar in nature. I want to hide these classes from the client by making them instantiable only through a static method in the superclass which returns a superclass reference to a subclass instance (the concrete class is determined by the method parameters). 
  So far so good, I believe that's a very common thing to do.</p>
  
  <p>Now, these subclasses I'm talking about can be divided into two groups, one group, whose members require two parameters in order to be constructed and another group, whose members need an additional parameter.</p>
  
  <p>So now my question is this: How can I let the client obtain both of these types via a static method like the one mentioned above. Do I provide two static methods with different paramter lists? Do I force the client to pass a zero on the third optional parameter that the first group doesnt need? Is there a design pattern for this? (I have considered the Builder pattern from Effective Java, but as far as I understnad it that ones usually used in a different context). Or do I modify my inheritance hierarchy?</p>
  
  <p>Any answers would be appreciated!</p>
  
  <p>EDIT:</p>
  
  <p>I believe my question is a little bit convoluted at the moment, all add a little bit of code to make it clearer:</p>
  
  <pre><code>abstract class SuperClass{
  
      public static SuperClass getSuperClass(String type, int i1, int i2, int optional) {
  
          /*
           *'type' alone determines which concrete subclass is instanciated
           *'optional' is only needed for the construction for some of those 'types'
           *so the implementation of this method might look like this:
           */
  
          switch(type) {
              case "1":
                  return new Subclass1(i1, i2);
                  break;
              case "2":
                  return new Subclass2(i1, i2, optional);
                  break;
  
          /*
           *So the problem is this: always passing 'optional' is weird if it 
           *is then simply discarded in some cases.
           *Overloading is weird as well because I don't want to split up 
           *the switch statement or check for exceptions in every case 
           *(when optional is/is not declared for types where it 
           *shouldn't/should be)
           */
      }
  
  }
  </code></pre>