I have a question about a problem I'm struggling with. I hope you can carry me.
Imagine that I have an Object class that represents the base class of a hierarchy of physical objects. Later I inherit it to create the classes Object1D, Object2D and Object3D. Each of these derived classes will have some specific methods and attributes. For example, a three-dimensional object may have functionality for loading a 3d model to be used by the visualizer.
So I would have something like this:
class Object {}; class Object1D : public Object { Point mPos; }; class Object2D : public Object { ... }; class Object3D : public Object { Model mModel; };
Now I will have a separate class called Renderer, which simply accepts the object as an argument and well does it :-) In a similar way, I would like to support various types of rendering. For example, I could use the default one that every object could rely on, and then provide other specific visualization tools for some objects:
class Renderer {};
And here is my problem. The renderer class must receive the object as an argument, for example, in the constructor, in order to get any data needed to render the object.
So far so good. But Renderer3D must receive the Object3D argument in order to get not only the basic attributes, but also the specific attributes of the 3D object.
Constructors will look like this:
CRenderer(Object& object); CRenderer3D(Object3D& object);
Now, how can I indicate this in a general way? Or better yet, is there a better way to develop it?
I know I can rely on RTTI or the like, but I would like to avoid this if possible, as I believe that is probably the best way to handle this.
Thanks in advance!