Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: Professional PHP Design Patterns
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 4th, 2013, 11:00 AM
Authorized User
Points: 69, Level: 1
Points: 69, Level: 1 Points: 69, Level: 1 Points: 69, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2012
Location: Indiana, United States
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
{
    private 
$_cd;

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

    public function 
__toString()
    {
        
$output '';

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

        return 
$output;
    }

And then use the code like so...

PHP Code:
$myCD = new CD;

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

$cdDecorator = new CDTrackListDecoratorCaps($myCD);

echo 
$cdDecorator
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?
Reply With Quote
  #2 (permalink)  
Old February 4th, 2013, 11:58 AM
Wrox Author
Points: 118, Level: 2
Points: 118, Level: 2 Points: 118, Level: 2 Points: 118, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2009
Location: Milwaukee, WI
Posts: 15
Thanks: 0
Thanked 4 Times in 4 Posts
Default

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!
__________________
-aaron
--
aaronsaray.com || <-- yeah... try it.
Reply With Quote
  #3 (permalink)  
Old February 5th, 2013, 08:48 AM
Authorized User
Points: 69, Level: 1
Points: 69, Level: 1 Points: 69, Level: 1 Points: 69, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2012
Location: Indiana, United States
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.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 01:36 PM
Desing Pattern tilakkalyan J2EE 3 February 14th, 2006 06:04 AM
DirectoryInfo.GetFiles(pattern): search pattern fo arif_1947 VS.NET 2002/2003 1 October 19th, 2004 11:59 PM



All times are GMT -4. The time now is 09:28 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.