title: Spring: Why do we autowire the interface and not the implemented class?
body: <p><strong>Example</strong></p>
  
  <pre><code>interface IA
  {
    public void someFunction();
  }
  
  @Resource(name="b")
  class B implements IA
  {
    public void someFunction()
    {
      //busy code block
    }
    public void someBfunc()
    {
       //doing b things
    }
  }
  
  @Resource(name="c")
  class C implements IA
  {
    public void someFunction()
    {
      //busy code block
    }
    public void someCfunc()
    {
       //doing C things
    }
  }
  
  class MyRunner
  {
  
    @Autowire
    @Qualifier("b") 
    IA worker;
  
    worker.someFunction();
  }
  </code></pre>
  
  <p>Can someone explain this to me. </p>
  
  <ul>
  <li>How does spring know which polymorphic type to use. </li>
  <li>Do I need <code>@Qualifier</code> or <code>@Resource</code>? </li>
  <li>Why do we autowire the interface and not the implemented class?</li>
  </ul>