Original Post
Currently I'm having a base interface "Extent" that Ray, Point, Sphere, AABB, etc. classes implements. The interface contains the method TestIntersection(Extent) that is used to test an arbitrary extent for intersection. The method consist of a series of if-else statements to check the type of the extent and then call appropriate intersection method (or throw a NotImplementedException if not possible to test for intersection). This design makes some sense since I test for containment as well as intersection so AABB-Sphere is not the same as Sphere-AABB so no duplicate code exist. Also I need to be able to test two arbitrary extents for intersection, i.e. unknownExtent.TestIntersection(unknownExtent2) works. However, I see a few problems with my current design: 1. My intersection algorithms are not in one place but spread across the code. 2. I feel that intersection code does not really belong in the Ray, Point, etc. classes. 3. I might in some cases want to only test for containment or intersection not both. I might want to be able to test for intersection as well as get the point/line of intersection. Then I'll need to add even more methods which will clutter my classes even more (or even worse result in duplicate code). So does anyone have any idea of how a good design might look like? Any design pattern that might be relevant here?