No, you don’t make variables for an animal’s traits, because those traits don’t change (disregarding evolution).
Firstly, you need a decent book on object-oriented design, rather than asking us to help. Take some initiative and do some research.
For the moment, how about just implementing some basic polymorphic boolean functions like IsTerrestrial()
, IsAquatic()
, etc… Maybe make an enumeration for AquaticType
that returns None
, FreshWater
, SaltWater
or Both
. You override these methods at the highest level possible so that your subtypes don’t have to worry.
For example, almost all fish are not terrestrial, so the subclasses of Fish
should not have to implement this method (the Fish
class should). Likewise, most mammals are not aquatic.
This is all a bit subjective. There are many ways to represent this information in a class hierarchy, but this should give you a start.
solved How I can implement this hierarchy? [closed]