OOP Design question.

I've been working with SDL2 the past several months and quite enjoy it. That being said I'm getting this feeling that I am not doing something right, or I have not learned something that I should have, in order to do this correctly.

Basically my problem is that in most all games I've been working on I have the standard Player class and Enemy class. They both have their own unique methods, however they also share IDENTICAL methods. Identical methods like Loading, Drawing, and Updating. Those 3 methods always have identical code and are pretty much copy pasted from one class to the other. Is this considered standard technique or should I be doing something like inheriting from a texture class that handles loading and drawing?
> should I be doing something like inheriting from a texture class that handles loading and drawing?

Either: containing an object of a texture class to which loading etc. are delegated.

Or: inheriting privately from a texture class and providing using-declarations for loading etc.
Those 3 methods always have identical code and are pretty much copy pasted from one class to the other.

Any time you see identical code in the same program it should raise a big red flag. Obviously it takes up space but it also makes the code fragile. If a bug gets fixed in one of the methods, there's a good chance that it won't get fixed in the others.

It seems to me that both the human and computer players in a game have a lot in common. There's loading, drawing and updating like you mentioned, but also things like inventory, health, location, etc. I'd consider having a Player class that encompasses all of this and then a Human class that derives from it to handle things that only a human player does.
Very much appreciate the replies folks. So it's a bit what I kind of expected. I'll get working on it!
Topic archived. No new replies allowed.