Hi again dear community, I have another conundrum for which that I request your counsel. Heavy sounding introductions aside, I think this should be an easy to answer question.
In the realms of OOP there is a tendency to 'over generalise'. I like to use abstract classes but to derive super specific use cases from them. In this case, I have a 'static mesh' class that I'm rather proud of, because it's one of the few things I've coded myself that works as expected. I'm sure many programmers have similar classes in their collection.
Up until now I've been merely playing around with the staticMesh class, setting shaders and shader uniforms in calling code and then calling the 'render' function from the calling code. However, now that my codebase is scaling up in terms of sophistication, I would like to create specific classes that inherit from staticMesh like "palmTreeMesh" that will use a vertexBasedLighting shader (no significant specular term to speak of)
and so will use a render function as follows:
//pseudo code!
void PalmTree::Render()
{
glUseProgram(texturedShader->getHandle());
texturedShader->UpdateUniforms("MVPMatrix",someValue);
texturedShader->UpdateUniforms("Time",someValue);
StaticMesh::Render();
}
StaticMesh::Render() has no business having its code cut and pasted into several different files, it's great how it is.
So the main crux of my inquiry is thus:
StaticMesh::Render is not 'pure virtual' so static mesh is not a abstract class. However I'd like to enforce use of inherited, specific meshes
and not messy, lazy code where everything is done in a calling class. How do I do this? Just use a pure virtual 'stub' like so:
class BaseClass
{
public:
virtual void DoSomething();
virtual void Stub() = 0;
};
class Derived : public BaseClass
{
public:
void DoSomething();
void Stub() {}; //declaration and definition of 'stub'
};
Or is there another alternative to this? Thanks in advance.