Is context inheritance, as shown by Head First Design Patterns' Duck example, irrelevant to strategy pattern?

Posted by Korey Hinton on Programmers See other posts from Programmers or by Korey Hinton
Published on 2013-06-29T22:02:41Z Indexed on 2013/06/29 22:27 UTC
Read the original article Hit count: 475

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:

Strategy Pattern

© Programmers or respective owner

Related posts about design

Related posts about design-patterns