title: C# - Determine which class an object should use on instantiation?
body: <p>I have 2 classes:  Entity and Control.</p>
  
  <p><strong>Entity:</strong> </p>
  
  <pre><code>public class Entity
  {
  
     public float Rotate {get; private set;}
  
     readonly Control m_Control
  
     public Entity(float rot)
     {
       Rotate = rot;
       m_control = new Control();
     }
  
      public void Update(float time)
      {
  
              switch (m_control.Rotating())
              {
                  case Control.Rotator.Right:
                      Rotate += time * 1.5f;
                      break;
                  case Control.Rotator.Left:
                      Rotate -= time * 1.5f;
                      break;
                  case Control.Rotator.Still:
                      break;
                  default:
                      break;          
              }
       }
  
  
  
  }
  
  </code></pre>
  
  <p><strong>Control:</strong></p>
  
  <pre><code>public class Control
  {
          private Random rnd = new Random();
          private int _randomTurn;
  
          public enum Rotator
          {
              Still,
              Right,
              Left
          }
  
          public Control()
          {
              TimerSetup(); // Initialize timer for Entity
          }
  
   public Rotator Rotating()
          {
  
                  switch(_randomTurn)
                  {
                      case 1:
                          return Rotator.Right;
                      case 2:
                          return Rotator.Left;
                      default:
                          return Rotator.Still;
                  }
  
              }
  
   private void TimerSetup()
   {
              DispatcherTimer dispatcherTimer = new DispatcherTimer();
              dispatcherTimer.Tick += new EventHandler(GameTickTimer_Tick);
              dispatcherTimer.Interval = new TimeSpan(0, 0, 2);
              dispatcherTimer.Start();
   }
  
  
   private void GameTickTimer_Tick(object sender, EventArgs e)
   {
       RandomTurn();
   }
  
  
   private void RandomTurn() 
   {
      _randomTurn = rnd.Next(1, 4);
   }
  
  
  }
  </code></pre>
  
  <p>Basically I want to make 'Control' class a base class and create two subclasses: PlayerControl and AIControl.  Currently both Player control inputs and AI control inputs are handled in the one Control class.</p>
  
  <p>My dilemma is, in the Entity class, how do I determine what Control class the Entity will use?</p>
  
  <p>The Entity class currently assigns the Control class like so:</p>
  
  <pre><code>readonly Control m_Control
  
  public Entity(float rot)
     {
       Rotate = rot;
       m_control = new Control();
     }
  </code></pre>
  
  <p>I instantiate multiple Entity classes in another class like so:</p>
  
  <pre><code>public class Environment
  {
  
  readonly Entity m_entity;
  readonly Entity m_entity2;
  
  public Environment()
  {
     m_entity = new Entity(90.0f);
     m_entity2 = new Entity(180.0f);
  }
  </code></pre>
  
  <p>Is there a way for me to determine what Control subclass the entity will use when instantiating it?</p>