class design question
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?
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 :
That would look more elegant, at least to me than
Really, overcomplicated class hierarchies tend to look cluttered, but I personally think this is an worthwhile distinction.
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 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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement