I'm trying to make a RTS game in C++ and I'm sort of worried I'm going to have issues later if I inherit too deeply. I'm sort of new to OOP, and I was wondering if anyone has more experience in this area and could tell me if I'm going overboard with my inheritance. This is currently how my game is laid out:
That looks like perfectly reasonable inheritance to me.
I have never heard of problems from inheriting too deeply (unless we are talking about problems with poorly planned inheritance trees, or inheritance that doesn't serve any actual purpose)
If you do want to simplify your implementation, you might try
Unit
Peasant
Native
Colonist
Soldier
Spearman
Musketeer
Building
House
Tent
Shack
Whether or not this is better mostly depend on, for example, how much Soldier code is shared by Spearman and Musketeer, compared to how much Spearman and Musketeer differ from each other.
Thanks, I think that Soldier units and peasant units are similar enough to be put together. I was just worried that things might get confusing if I had too much inheritance. I guess it will be alright as long as I don't start using MI and that kind of crazy stuff.
I think that having extra levels of inheritance is a more harmless example of overengineered code. Try not to add levels of abstraction or indirection before you actually find that they will help you. And don't waste too much time thinking about things like this, it's crippling!