I have a problem keeping my code maintainable. In my problem I have defined a 'RenderableShape' that is the parent interface of both 2D and 3D shapes (those two are interfaces).
I have a Renderer class that 'asks' a RenderableShape
for the data to render.
A 3D shape should return some mathematical formula or object wrapped around that and a 2D shape returns all its 2D shapes it consists of (triangles, circles etc.).
Obviously 'RenderableShape' cannot return both types two the renderer.
I could make two different methods, but that would force all implementations to implement a useless method.
The renderer can also ask for the shape what kind it is, but you would need a cast afterwards, which should not only be unnecessary, but would also be too slow to use in rendering.
Furthermore, the rendering code should not be in shapes themselves, since I would like to have all rendering code in a renderer, to allow for different renderer types (Z-Buffer, raytracer etc.)
What would be a maintainable and preverably efficient approach to this problem?