Wrox Programmer Forums
BOOK: Professional PHP Design Patterns
This is the forum to discuss the Wrox book Professional PHP Design Patterns by Aaron Saray ISBN: 978-0-470-49670-1
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional PHP Design Patterns section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 4th, 2013, 12:00 PM
Authorized User
Join Date: Sep 2012
Posts: 13
Thanks: 3
Thanked 1 Time in 1 Post
Default Decorator Pattern

While reviewing the decorator pattern in chapter six, I notice that the decorating object actually modified the original object data.

So my question is would it be better to have the decorator not modify the original object?

A possible way of doing this is:

PHP Code:
class CDTrackListDecoratorCaps

    public function 
__construct(CD $cd)
$this->_cd $cd;

    public function 
$output '';

        foreach (
$this->_cd->trackList as $track) {
$output .= ($num +1) . ") ".strtoupper($track)." ";


And then use the code like so...

PHP Code:
$myCD = new CD;

$myCD->addTrack('Song A');

$cdDecorator = new CDTrackListDecoratorCaps($myCD);

This allows for a more flexible use of the CD instance because I am not changing the values within the instance.

Am I wrong and completely insane?
Old February 4th, 2013, 12:58 PM
Wrox Author
Join Date: Sep 2009
Posts: 15
Thanks: 0
Thanked 4 Times in 4 Posts

Hey - great idea.

Looking back, I would have made a few more examples a bit differently. :) Glad to see you understand the decorator pattern! Keep it up!
aaronsaray.com || <-- yeah... try it.
Old February 5th, 2013, 09:48 AM
Authorized User
Join Date: Sep 2012
Posts: 13
Thanks: 3
Thanked 1 Time in 1 Post
Default Great Author

Overall, I think your book is really good, and has helped me understand design patterns as they relate to PHP. Have you thought of creating a second edition? Maybe including some of the PHP 5.3 / 5.4, composer, and other "new" PHP goodies.

Just sayin'. I would buy it.

Similar Threads
Thread Thread Starter Forum Replies Last Post
State pattern versus Strategy Pattern disel2010 BOOK: Professional ASP.NET Design Patterns 2 March 15th, 2011 08:20 AM
design pattern kishore.dyn Struts 1 February 14th, 2006 02:36 PM
Desing Pattern tilakkalyan J2EE 3 February 14th, 2006 07:04 AM
DirectoryInfo.GetFiles(pattern): search pattern fo arif_1947 VS.NET 2002/2003 1 October 19th, 2004 11:59 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.