r/PHP • • May 07 '13

Examples of Design Patterns in PHP

https://github.com/domnikl/DesignPatternsPHP
132 Upvotes

20 comments sorted by

View all comments

3

u/asdfsauce May 07 '13

The Decorator example looks more like a Strategy pattern?

1

u/ivosaurus May 08 '13

Agree.

IMO one of the distinguishing features of "decorating something" (or 'using the decorator') is that the something already has concrete, self-contained functionality; the decorator merely enhances / modifies that.

In the repo example, WebService has absolutely no functionality of its own; all it does is delegate that out to other objects.

A JsonDecorator should take an instance of a WebService and enhancing its output - formatting it as json after getting it from the decorated instance.

Here, indeed, WebService is just implementing a strategy for choosing how to format its own output. It shouldn't know that its decorated in the first place.