0

I have a class called Drawable which defines the basic attributes a object needs to be rendered using openGL. So i have a drawable class, and then a Model class.

class Drawable
{
public:
    // add functions to load data
private:
    std::vector<GLfloat> _vertices;
    std::vector<GLuint> _indices;
    std::vector<GLTexture> _textures;

    glm::mat4 _model, _view, _projection;
    GLint _modelLoc, _viewLoc, _projLoc;
};

When should I inherit a class, and when should I just create a object of the class in my new class?

class Model : public Drawable
{

};

or

class Model
{
public:
    // stuff here
private:
    Drawable _drawable;
};
  • 1
    This sort of question can generate a lot of controversy. I find, as a first step, that it is worth asking, in your case, "Is a Model a Drawable? (inheritance)", or "Does a Model have a Drawable? (inclusion)" This doesn't always dictate what is best, but it's a good first step. – md5i Jun 07 '16 at 04:06
  • Ah, so it's probably a model is a drawable. I assume it doesn't really matter then. I just wanted to make sure there weren't any standards in place – Omar Martinez Jun 07 '16 at 04:08
  • Here are other dupes: [Inheritance or composition: Rely on “is-a” and “has-a”?](http://stackoverflow.com/q/453738/514235), [interface vs composition](http://stackoverflow.com/q/10334915/514235), [Inheritance vs Composition:: Is my understanding correct?](http://stackoverflow.com/q/29427621/514235), – iammilind Jun 07 '16 at 04:09

0 Answers0