Elisabeth Robson

Reader question: case studies for Design Patterns

Posted in Blog, Reader Question, Technology by Elisabeth on October 23, 2011

I got a question today from Rahul, a reader of Head First Design Patterns, who asked for recommendations for how to find case studies with design patterns he could use to apply what he’s learned from the book.

One of my favorite design patterns-related sites is the design patterns wiki. Most of the great information is in the discussions around the patterns, and many of the users who have contributed to these discussions talk about specific use-cases of these patterns in real-world situations. So that’s a great place to start.

And of course, there’s always search. Try searching on “design patterns case studies” and you’ll find lots of great starting points.



Strategy Pattern in PHP

Posted in Blog, Reader Question, Technology by Elisabeth on October 13, 2011

Over the years since we published Head First Design Patterns, we’ve had several people generously take on the task of porting the Java code to other languages, including C++ and C#. I most recently came across this version of the Duck Simulator (the Strategy Pattern) in PHP: http://idhana.com/2011/10/12/design-pattern-strategy-in-php/.

One of the nice things about Design Patterns is that they can be applied in almost any language. In the original “Gang of Four” patterns book, Design Patterns: Elements of Reusable Object-Oriented Software by Gamma et. al., the examples are implemented in C++ and Smalltalk, and there have been many other design patterns books that have used a variety of languages. The key is understanding the principles rather than a specific implementation.

The Strategy Pattern is about interchangeable behavior that an object can use. In our Duck Simulator, the ducks might have different flying behavior or quacking behavior, so we create interchangeable classes that represent the different behaviors. From the point of view of the duck object, it doesn’t really matter which specific behavior it’s using because they are interchangeable. This concept is applicable in any language (and can be implemented in a variety of different ways).

If you’ve implemented the patterns from Head First Design Patterns in a language other than Java, and would be interested in sharing your implementation, definitely let us know!



Tagged with: ,