In “Head First Design Patterns,” there is an example involving flying behavior of ducks that gets refactored because there is a combination of flying ducks (eg Mallards) and non-flying ducks (eg, rubber duckies), which makes sense since since mallards fly but rubber duckies don’t. I would have guessed that the rubber duckies would just omit any reference to flying behavior, but in the diagram from the book, they implement the FlyNoWay class, which inherits from the FlyBehavior interface. Why doesn’t it just skip the whole question? I.e., why does it need to implement FlyNoWay when the fly() function will in that case just consist of the empty function that does nothing? Any help is greatly appreciated, thank you.
Hank is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.