Jump to content
  • Advertisement
Sign in to follow this  
spunkybuttockszc

class design question

This topic is 4912 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here's a small portion of the class hierarchy pertaining to bullets for a '1945' clone: GameEntity -----Bullet_Generic ----------Bullet_Normal ----------Bullet_Homing ----------Bullet_Exploding 'Bullet_Generic' contains only one extra member that GameEntity, and no new methods. Since the difference between 'Bullet_Generic' and 'GameEntity' is so small, would it still be considered good OOP design to have the class? Or should I just not have a base class for bullets?

Share this post


Link to post
Share on other sites
Advertisement
It could be useful, if you wanted to make a container for all types of bullets, like this, altough I'd personally call it Projectile, for the possibility to add stuff like missiles to it :

Bullet_Generic* bullets[x];

That would look more elegant, at least to me than

GameEntity* bullets[x];

Really, overcomplicated class hierarchies tend to look cluttered, but I personally think this is an worthwhile distinction.

Share this post


Link to post
Share on other sites
I think it is a good idea to limit the depth of hierarchies to three or less levels when possible. A deep hierarchy is difficult to use.

Since your hierarchy is only 3 deep, I don't see a need to simplify it. But if you feel the need to remove a level...

I think it is a bad idea to merge Generic_Bullet into GameEntity even if the difference is small. That would effectively turn all GameEntity's into Generic_Bullets (even though the name would remain the same). It is a better idea to move the implementation of Generic_Bullet into all its sub-classes, if the amount of duplication is small. If the amount of duplication is large, then you should just leave everything the way it is.

In general, when choosing between correctness and convenience, correctness is the best choice in the long run, but that doesn't mean it is always the best choice.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!