<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Decorator Pattern</title>
	<atom:link href="http://www.phpdesignpatterns.com/design-patterns/pattern-decorator/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.phpdesignpatterns.com</link>
	<description>Tutorials and Examples of Design Patterns in PHP</description>
	<lastBuildDate>Wed, 25 Aug 2010 02:53:49 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: thinsoldier.com</title>
		<link>http://www.phpdesignpatterns.com/design-patterns/pattern-decorator/comment-page-1/#comment-4</link>
		<dc:creator>thinsoldier.com</dc:creator>
		<pubDate>Fri, 05 Feb 2010 21:20:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpdesignpatterns.com/?page_id=44#comment-4</guid>
		<description>[...] This is a comment I had about an article on the Decorator pattern  [...]</description>
		<content:encoded><![CDATA[<p>[...] This is a comment I had about an article on the Decorator pattern  [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: thinsoldier</title>
		<link>http://www.phpdesignpatterns.com/design-patterns/pattern-decorator/comment-page-1/#comment-3</link>
		<dc:creator>thinsoldier</dc:creator>
		<pubDate>Fri, 05 Feb 2010 21:11:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpdesignpatterns.com/?page_id=44#comment-3</guid>
		<description>Very easy to understand but I think some people may overlook the importance/usefulness of the decorator pattern since all you&#039;re doing in the examples could be accomplished by just concatenating P and /P around the getData() wherever it is you were going to display it.

I find the decorator pattern is best for when you have a lot of parts to the data that need a lot of manipulation of their values and a lot of html but not so much html that it warrants a full page/template/view.

For example in my (poorly written) real estate site I have an object that represents a property for sale in the listings table of the DB. All 126 fields of the property record!

When it&#039;s time to show info about the property to a visitor I only need to show them about a dozen fields. But most of those fields need to be manipulated. I need to ucfirst() the property status text, convert the price to Euros/Pounds/USD/BSD, attach the http://www.site.com/listings/... onto the permalink text of the listing, convert 3.5 into &quot;3 1/2 Bath&quot;, convert the square feet values into Acres if they are over 1 acres in size and lots of other stuff. Also all these fields had to be wrapped in html tags and ids and css classes etc.

At first I had all that stuff as part of the code that happens _before_ the data is saved to the database. Then other clients came along who wanted the same system (but different) and I realized a lot of those manipulations were only relevant to the site visitors. So then I put those instructions in the main class file as $listing-&gt;displayOverview() method. 

But then some more clients came along who wanted something other than the default set of info in the default format. Some clients wanted the category value to link to a search results page of everything in that category. Some wanted the neighbourhood value to do the same. Some didn&#039;t want the category or neighbourhood value to be shown. Sure I could have just use css to hide the neighbourhood span but some high end clients don&#039;t want anyone to know where their house is located so the neighbourhood/address values weren&#039;t allowed to be anywhere in the markup. They had to be taken out at the code level.

It unfortunately took a looong time and a lot of clients on this system to realize I needed to take this segment of my code and turn it into a custom decorator for each client that needed one.

Before that realization, at one point I had a site identifier variable and a ton of IF statements strewn throughout the code that made it a nightmare to read!

For another good example of decorator usage see this Zend Framework Zend_Form screencast (requires having a zend.com account): http://www.zend.com/en/webinar/Framework/webinar-leveraging-zend_form-decorators-20091216.flv</description>
		<content:encoded><![CDATA[<p>Very easy to understand but I think some people may overlook the importance/usefulness of the decorator pattern since all you&#8217;re doing in the examples could be accomplished by just concatenating P and /P around the getData() wherever it is you were going to display it.</p>
<p>I find the decorator pattern is best for when you have a lot of parts to the data that need a lot of manipulation of their values and a lot of html but not so much html that it warrants a full page/template/view.</p>
<p>For example in my (poorly written) real estate site I have an object that represents a property for sale in the listings table of the DB. All 126 fields of the property record!</p>
<p>When it&#8217;s time to show info about the property to a visitor I only need to show them about a dozen fields. But most of those fields need to be manipulated. I need to ucfirst() the property status text, convert the price to Euros/Pounds/USD/BSD, attach the <a href="http://www.site.com/listings/.." rel="nofollow">http://www.site.com/listings/..</a>. onto the permalink text of the listing, convert 3.5 into &#8220;3 1/2 Bath&#8221;, convert the square feet values into Acres if they are over 1 acres in size and lots of other stuff. Also all these fields had to be wrapped in html tags and ids and css classes etc.</p>
<p>At first I had all that stuff as part of the code that happens _before_ the data is saved to the database. Then other clients came along who wanted the same system (but different) and I realized a lot of those manipulations were only relevant to the site visitors. So then I put those instructions in the main class file as $listing-&gt;displayOverview() method. </p>
<p>But then some more clients came along who wanted something other than the default set of info in the default format. Some clients wanted the category value to link to a search results page of everything in that category. Some wanted the neighbourhood value to do the same. Some didn&#8217;t want the category or neighbourhood value to be shown. Sure I could have just use css to hide the neighbourhood span but some high end clients don&#8217;t want anyone to know where their house is located so the neighbourhood/address values weren&#8217;t allowed to be anywhere in the markup. They had to be taken out at the code level.</p>
<p>It unfortunately took a looong time and a lot of clients on this system to realize I needed to take this segment of my code and turn it into a custom decorator for each client that needed one.</p>
<p>Before that realization, at one point I had a site identifier variable and a ton of IF statements strewn throughout the code that made it a nightmare to read!</p>
<p>For another good example of decorator usage see this Zend Framework Zend_Form screencast (requires having a zend.com account): <a href="http://www.zend.com/en/webinar/Framework/webinar-leveraging-zend_form-decorators-20091216.flv" rel="nofollow">http://www.zend.com/en/webinar/Framework/webinar-leveraging-zend_form-decorators-20091216.flv</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>

