News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Label Media Blog:
Design Patterns in PHP - Decorator Pattern
December 08, 2010 @ 09:13:55

Tom Rawcliffe has posted the latest installment of his look at design patterns in PHP. This time his focus is on the Decorator pattern.

Continuing my series on PHP design patterns, today it's the turn of the Decorator. In contrast to last week's Strategy Pattern which is used to change the 'úguts'Ě of a class, the Decorator Pattern is used to extend the behavior of a class with different functionality at run time. This is achieved by implementing a 'údecorator'Ě class that implements the same interface as the object that you wish to 'údecorate'Ě and wraps it's content.

The Decorator pattern lets you "decorate" your objects with additional features. He illustrates with a sample "Property" class (that implements an interface) that he wants to extend past the normal property handling. He add a "PropertyDecorator" to the mix that lets it use deocrators for uppercasing and padding the string. There's an example script included at the end that shows how to put it all to use.

0 comments voice your opinion now!
decorator designpattern tutorial property


blog comments powered by Disqus

Similar Posts

Cohesive Web: PHP serialization or Json

SitePoint PHP Blog: Building a Live-score Widget Using PHP Web Sockets

EchoDitto Labs Blog: How to Configure Eclipse PDT with Zend Server Debugger on MAMP for Drupal

Devshed: The Basics of Using the Prototype Pattern with PHP 5

Adrian Schneider's Blog: Caching Zend Framework Forms


Community Events





Don't see your event here?
Let us know!


interview opinion version introduction library composer artisanfiles framework tool voicesoftheelephpant language release conference list community podcast symfony series laravel security

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework