title: When and why should the Strategy Pattern be used?
body: <p>When would the <a href="http://en.wikipedia.org/wiki/Strategy_pattern" rel="noreferrer">Strategy Pattern</a> be used?</p>
  
  <p>I see client code snippets like this:</p>
  
  <pre>
  <code>
  class StrategyExample {
  
      public static void main(String[] args) {
  
          Context context;
  
          // Three contexts following different strategies
          context = new Context(new ConcreteStrategyAdd());
          int resultA = context.executeStrategy(3,4);
  
          context = new Context(new ConcreteStrategySubtract());
          int resultB = context.executeStrategy(3,4);
  
          context = new Context(new ConcreteStrategyMultiply());
          int resultC = context.executeStrategy(3,4);
  
      }
  
  }
  </code>
  </pre>
  
  <p>and it looks like you could just refactor it to this:</p>
  
  <pre>
  <code>
  class StrategyExample {
  
      public static void main(String[] args) {
           // Three contexts following different strategies
          int resultA =new ConcreteStrategyAdd().execute(3,4);
          int resultB =new ConcreteStrategySubtract().execute(3,4);
          int resultC =new ConcreteStrategyMultiply().execute(3,4);
      }
  
  }
  </code>
  </pre>
  
  <p>The first section of code was taken directly from the wikipedia page.  One big difference is the context goes away, but it wasn't doing anything in the example anyway.  Maybe someone has a better example where Strategy makes sense.  I usually like design patterns but this one seems to add complexity without adding usefulness.</p>