Is context inheritance, as shown by Head First Design Patterns' Duck example, irrelevant to strategy pattern?
- by Korey Hinton
In Head First Design Patterns it teaches the strategy pattern by using a Duck example where different subclasses of Duck can be assigned a particular behavior at runtime. From my understanding the purpose of the strategy pattern is to change an object's behavior at runtime. Emphasis on "an" meaning one.
Could I further simplify this example by just having a Duck class (no derived classes)? Then when implementing one duck object it can be assigned different behaviors based on certain circumstances that aren't dependent on its own object type. For example: FlyBehavior changes based on the weather or QuackBehavior changes based on the time of day or how hungry a duck is.
Would my example above constitute the strategy pattern as well?
Is context inheritance (Duck) irrelevant to the strategy pattern or is that the reason for the strategy pattern?
Here is the UML diagram from the Head First book: