title: Avoid switch-case condition using design patterns
body: <p>I have a few classes which represent arithmetic operations (Plus, Minus, Pow...) in Java which extend the same abstract class <code>Operator</code> but they differ in one method -<code>calculate</code>.</p>
  <p>I'm trying to find a way to avoid the switch-case conditions in order to implement these classes in the right way using design patterns (new to design patterns), but how do I do it? Or is the switch-case statement is the right way to implement it?</p>
  <p>here is the abstract class:</p>
  <pre><code>public abstract class Operator {
  
      private int a, b;
      
      public Operator(int a, int b){
          this.a = a;
          this.b = b;
      }
      
      public float calculate() {
          // here I want to return the result depending on the operator. If Plus extends Operator then the returned value is this.a + this.b
      }
      
      public void print() {
          System.out.println(&quot;This is the result : %f&quot;, this.calculate());
          
      }
  }
  
  </code></pre>