class design question

Started by
1 comment, last by JohnBolton 19 years, 2 months ago
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?
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.
I teleported home one night; With Ron and Sid and Meg; Ron stole Meggie's heart away; And I got Sydney's leg. <> I'm blogging, emo style
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.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!

This topic is closed to new replies.

Advertisement