In an attempt to fully understand how to solve Java\'s multiple inheritance problems I have a classic question that I need clarified.
Lets say I have class Ani
May I suggest the concept of Duck-typing?
Most likely you would tend to make the Pegasus extend a Bird and a Horse interface but duck typing actually suggests that you should rather inherit behaviour. As already stated in the comments, a pegasus is not a bird but it can fly. So your Pegasus should rather inherit a Flyable
-interface and lets say a Gallopable
-interface.
This kind of concept is utilized in the Strategy Pattern. The given example actually shows you how a duck inherits the FlyBehaviour
and QuackBehaviour
and still there can be ducks, e.g. the RubberDuck
, which can't fly. They could have also made the Duck
extend a Bird
-class but then they would have given up some flexibility, because every Duck
would be able to fly, even the poor RubberDuck
.