Sign in to follow this  

class design question

This topic is 4695 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
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

This topic is 4695 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this