title: Use different methods based on parameter from constructor
body: <p>I have a class that should have slightly different method implementations based on a parameter I would pass to the class constructor. However, I would like to select which implementation to run at the time of the object creation, and not by always testing a specified parameter. Something of this sort:</p>
  
  <pre><code>public class SomeClass(){
      int parameter=-1;
  
      SomeClass(int param){
          this.parameter = param;
      }
  
      public methodSpecific(){ //For when parameter==1;
          Do stuff...
      }
  
      public methodSpecific(){ //For when parameter==2;
          Do stuff...
      }
  }
  </code></pre>
  
  <p>Instead of:</p>
  
  <pre><code>public class SomeClass(){
      int parameter=-1;
  
      SomeClass(int param){
          this.parameter = param;
      }
  
      public methodForAll(){ 
          switch(parameter){
              case 1:
                  Do something...
  
              case 2:
                  Do something else...
          }
      }
  }
  </code></pre>
  
  <p>Is there some way I can achieve this?</p>
  
  <p><strong>EDIT:</strong>
  This edit is to clarify the situation and context. Please consider the figure bellow. Rectangles of the same color mean that the implementation of those methods are the same. Rectangles with different colors means even though the name is the same the implementation differs. I need to find a way to implement classA and classB, but without duplicated code, and still allow for class "main" to know that both classA and classB have the same method names and variables.</p>
  
  <p><a href="https://i.stack.imgur.com/rsV92.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rsV92.png" alt="Ilustrative figure"></a></p>