title: How to correctly implement strategy design pattern
body: <p>I'm trying to implement strategy design pattern, and want to know if I do it correctly.</p>
  
  <p>Lets say, I have class <code>FormBuilder</code> which uses strategy from list below to build the form:</p>
  
  <ul>
  <li><code>SimpleFormStrategy</code></li>
  <li><code>ExtendedFormStrategy</code></li>
  <li><code>CustomFormStrategy</code></li>
  </ul>
  
  <p>So the questions are:</p>
  
  <ol>
  <li>Is it correct to select strategy inside <code>FormBuilder</code>, and not passing strategy from outside?</li>
  <li>Doesn't this violates open closed principle? So, if I want to add one more form strategy or to remove an existing one, I have to edit the <code>FormBuilder</code> class.</li>
  </ol>
  
  <p>Draft code example</p>
  
  <pre class="lang-js prettyprint-override"><code>class Form {
      // Form data here
  }
  
  interface IFormStrategy {
      execute(params: object): Form;
  }
  
  class SimpleFormStrategy implements IFormStrategy {
      public execute(params: object): Form {
          // Here comes logics for building simple form
          return new Form();
      }
  }
  
  class ExtendedFormStrategy implements IFormStrategy {
      public execute(params: object): Form {
          // Here comes logics for building extended form
          return new Form();
      }
  }
  
  class CustomFormStrategy implements IFormStrategy {
      public execute(params: object): Form {
          // Here comes logics for building custom form
          return new Form();
      }
  }
  
  class FormBuilder {
      public build(params: object): Form {
          let strategy: IFormStrategy;
  
          // Here comes strategy selection logics based on params
  
          // If it should be simple form (based on params)
          strategy = new SimpleFormStrategy();
          // If it should be extended form (based on params)
          strategy = new ExtendedFormStrategy();
          // If it should be custom form (based on params)
          strategy = new CustomFormStrategy();
  
          return strategy.execute(params);
      }
  }
  </code></pre>