title: How to resolve class type using enum
body: <p>I have a group of classes (following strategy pattern) in my project. In the main function, I receive an enum value from the server and based on that I create an object of the base class type.</p>
  
  <p>I am using switch/case statement to achieve this. I read somewhere that the Open/Closed  principle does not allow opening a function to add a new case statement whenever a new class is added.</p>
  
  <p>I am thinking of using a <code>Activator.CreateInstance()</code>. Is there any drawback to it.</p>
  
  <p>Is there any other way to create an object from the enum type?</p>
  
  <p>Adding example below even though it is not a full fledged Strategy pattern</p>
  
  <pre><code>abstract public class Mammal
  {
     public abstract void MakeSound()
  }
  
  class Cat:Mammal
  {      
      public override  void MakeSound()
      {
          Console.WriteLine("Meow");        
      }    
  }
  
  class Dog:Mammal
  {
  
      public override void MakeSound()
      {
           Console.WriteLine("Bow");        
      }    
  }
  
  Main()
  {
  
      MammalTypes mammalType = RecieveValueFromServer();
      Mammal mammalBase
      switch(mammalType) // need to make this dynamic depending upon Enum type
      {
          case MammalTypes.Cat:mammalBase = new Cat()
                               break;
          case MammalTypes.Dog:mammalBase = new Dog()
                               break;            
      }
  
      mammalBase.MakeSound()
  }
  </code></pre>