title: design an abstract class so that any one can extend it and use the extended class polymorphically
body: <p>I want to have an abstract class like this:</p>
  
  <pre><code>public abstract Operator {
  
      public int[] operands;
  
      public Operator(int[] operands) {
          this.operands = operands;
      }
  
      public abstract int getOperatorResult();
  }
  </code></pre>
  
  <p>And some operators to extend from it like:</p>
  
  <pre><code>public class Add extends Operator {
  
      public Add(int[] operands) {
          super(operands);
      }
  
      public int getOperatorResult() {
          return operands[0] + operands[1];
      }
  }
  </code></pre>
  
  <p>And an OperatorCreator which gets an expression like "1+1" and returns the appropriate Operator's sub-class(in this case Add):</p>
  
  <pre><code>public class OperatorCreator {
  
      public static Operator getInstance(String expr) {
          ...
      }
  }
  </code></pre>
  
  <p>The main problem:
  And I want to let others to design their own operators by extending Operator class. And use their operators  polymorphically. something like this:</p>
  
  <pre><code>public class Main {
  
      public static void main(String[] args) {
          Operator op = OperatorCreator.getInstance("1-2");
          System.out.println(op.getOperatorResult());
      }
  }
  </code></pre>
  
  <p>How can I do this?</p>
  
  <p>Edit:
  I know it is possible using reflection. But I'd rather not to use reflection if it is possible. And I know I can let the designer of the Operator's sub-class register her new class using invoking a method at runtime. But I don't want to use this method.</p>
  
  <p>Thanks!</p>