Matt Iversen b8381e5a60 Proper example of Decorator pattern
Previous example was simply implementing a strategy pattern.

A key problem is that WebService made clear that it did no actual output of its own - it handed it off to 'decorators'.

A decorator should always wrap a class that already has its own complete, self-contained functionality.

In this way, they only enhance / modify it. An instance that is non-decorated should work fully by itself.

Note the distinguishing difference between this and sub-classing - here the enhancement is added dynamically, at runtime, and to one instance.

With sub-classing, the enhancement is added at compile / parse time, and is applied to all instances / uses of the subclass.
2013-05-10 11:14:19 +02:00
2011-08-23 11:52:46 +02:00
2011-08-23 11:52:46 +02:00
2013-05-09 10:11:42 +02:00
2011-08-23 11:52:46 +02:00
2011-08-27 10:54:30 +02:00
2013-05-08 01:06:11 +08:00
2013-05-08 15:30:54 +04:00
2011-09-03 12:57:28 +02:00
2012-09-01 11:05:56 +02:00
2011-11-19 10:12:05 +01:00
2011-10-30 11:51:39 +01:00
2011-10-04 12:08:37 +02:00

design patterns in PHP

This is a collection of known design patterns and some sample code how to implement them in PHP. Every pattern has a small list of examples (most of them from Zend Framework or Doctrine2 as I'm most familiar with this software).

I think the problem with patterns is that often people do know them but don't know when to apply which.

Please feel free to fork and add your own examples!

Languages
PHP 85.3%
Python 8%
Makefile 6.2%
Dockerfile 0.5%