title: What design pattern handles every combination of inherited classes?
body: <p>I have an abstract class with a few inheriting classes that represent shapes and I would like to test for collisions. For now, here is my (Java) code:</p>
  
  <pre><code>public abstract class Shape {
    public abstract boolean collision(Rectangle rectangle);
    public abstract boolean collision(Circle circle);
  }
  
  public class Rectangle extends Shape {
    // implementation of both abstract methods
  }
  
  public class Circle extends Shape {
    // implementation of both abstract methods
  }
  </code></pre>
  
  <p>I see the flaw in my code: I have to modify every class if I want to add another child class, say <code>Triangle</code>. Not to mention that the parent class must know all its children (as pointed out @deceze).</p>
  
  <p>I still would like to be certain that every collision is possible (Rectangle-Rectangle, Circle-Circle, Rectangle-Circle and Circle-Rectangle, plus the 5 more that Triangle would introduce, and so on).</p>
  
  <p>Is there a design pattern that I haven't thought of that solves that problem nicely?</p>