title: What is wrong with testing an object to see if it implements an interface?
body: <p>In the comments of <a href="https://stackoverflow.com/questions/7671121/what-is-the-name-of-this-bad-practice-anti-pattern/7671225#7671225">this answer</a> it is stated that "<strong><em>checking whether the object has implemented the interface</em></strong> <em>, rampant as it may be, is a bad thing</em>"</p>
  
  <p>Below is what I believe is an example of this practice:</p>
  
  <pre><code>public interface IFoo
  {
     void Bar();
  }
  
  public void DoSomething(IEnumerable&lt;object&gt; things)
  {
     foreach(var o in things)
     {
         if(o is IFoo)
             ((IFoo)o).Bar();
     }
  }
  </code></pre>
  
  <p>With my curiosity piqued as someone who has used variations of this pattern before, I searched for a good example or explanation of why it is a bad thing and was unable to find one.</p>
  
  <p>While it is very possible that I misunderstood the comment, can someone provide me with an example or link to better explain the comment?</p>