Alright lets say I have a cPlayer class that inherits from cOrganism, which inherits from cEntity. Now I’m ready to expand my cPlayer class and i want to add animation to my player. Would it be better to
A.) Create a cAnimation class and have cPlayer inherit from it?
B.) Create a cAnimation class and have it passed to cPlayer as an argument?
C.) Something else?
It depends on how
CAnimationis designed. In general, inheritance forms either a “Implements” or “Is a” relationship between the parent and child classes.For example,
cPlayershould inheritcAnimationwent you want either:cPlayerto implement the interfacecAnimationcPlayerto be acAnimation.Neither seem to make any sense to me. “cAnimation” is not the kind of name you’d give an interface, and a player is not an animation.
But this is just based on your naming. Your actual design is going to depend on the relationships between what’s controlling the animation, how it interacts with objects (maybe you need a
IAnimatedObjectinterface?), etc.