title: Interface or switch statement, finding the right pattern
body: <p>This question has probably been posted before, but I couldn't find it. </p>
  
  <p>I've been writing this sort of thing for so long, I sit down to write something new and just start typing this as if it were my own pattern. A project came up recently and I found myself looking at my own code and started thinking how smelly it looks. </p>
  
  <pre><code> BackgroundInfoIfYouCare
  </code></pre>
  
  <p>In this particular library I need to send out emails to users. So far there are 13 canned emails. </p>
  
  <p>Each email has it's own template (I'm using a Razor parser, so the templates are written in cshtml). 
  Each email template has a Name Key of string.
  Each email has it's own EF4 query to return a model based on a "membership" entity and all related data.</p>
  
  <p>I have a class that accepts a string which is a Email Template Name Key. </p>
  
  <p>The method will run the appropriate query and get back a list, grabs the email template.</p>
  
  <p>The list and template are passed to a parser to merge each of the memberships to the template and returns a list emails. </p>
  
  <pre><code> EndOfBackgroundInfoIfYouCare
  </code></pre>
  
  <p>So the real question...  what is the best way to do this?</p>
  
  <p>One way is to just use a switch</p>
  
  <pre><code>public List&lt;Membership&gt; Execute(string TemplateKey) {
  switch (TemplateKey) 
          {
              case "SomethingExpired":
                  QueryResult = new SomethingExpiredEmailQuery().ExecuteQuery();
                  break;
              case "SomethingExpireIn30":
                  QueryResult = new SomethingExpireIn30EmailQuery().ExecuteQuery();
                  break;
              case "FirstTimeLoginThanks":
                  QueryResult = new FirstTimeLoginThanksEmailQuery().ExecuteQuery();
                  break;
              case "SecurityTraining":
                  QueryResult = new SecurityTrainingEmailQuery().ExecuteQuery();
                  break;
              case ETC ETC ETC...
  </code></pre>
  
  <p>}</p>
  
  <p>Another way would be to use an interface</p>
  
  <pre><code>IEmailQuery
  void ExecuteQuery()
  </code></pre>
  
  <p>But if I use an interface I will still need to instantiate the Query class. It saves no code and does not make the code easier to maintain.</p>
  
  <p>With reflection I could do something like name all of the Email queries with a pattern:
  Email Template Key of SecurityTraining has a query name of SecurityTrainingEmailQuery and I could use reflection to instantiate and call the ExecuteQuery method. </p>
  
  <p>Without using reflection, is there no cleaner way of wiring this up? </p>