<?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/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
	>
<channel>
	<title>Comments on: ActionScript 3.0 and PHP 5: Doing Design Patterns</title>
	<atom:link href="http://www.as3dp.com/2009/05/25/actionscript-30-and-php-5-doing-design-patterns/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.as3dp.com/2009/05/25/actionscript-30-and-php-5-doing-design-patterns/</link>
	<description>OOP Techniques for Flash and Flex Developers</description>
	<lastBuildDate>Wed, 10 Mar 2010 17:32:01 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: William B. Sanders</title>
		<link>http://www.as3dp.com/2009/05/25/actionscript-30-and-php-5-doing-design-patterns/comment-page-1/#comment-2506</link>
		<dc:creator>William B. Sanders</dc:creator>
		<pubDate>Fri, 05 Jun 2009 09:50:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=997#comment-2506</guid>
		<description>Hi Daniel,

Thanks for the link. I looked at it, and while I did not come any closer to solving the riddle of how to code to an interface instead of an implementation in PHP, it&#039;s a very good PHP site. One of the insights that I liked very much is Will Fitch&#039;s observation that the Factory Pattern (I believe he actually meant Factory Method Pattern) can be used instead of the Singleton. I think that may be useful for those who want Singleton functionality but who do not like the Singleton&#039;s problems (see &lt;a href=&quot;http://www.as3dp.com/2008/11/26/we-don’t-need-no-stinkin’-singletons-why-to-avoid-the-singleton-pattern-in-actionscript-30-programming/&quot; rel=&quot;nofollow&quot;&gt;We Don&#039;t Need No Stinkin&#039; Singletons&lt;/a&gt;).

I don&#039;t mean to sound like I&#039; being a purist (and certainly not a prig!) about OOP and Design Patterns. I want to be as inclusive as possible when it comes to OOP/DP. Rather, I&#039;m looking for a way to use design patterns with PHP. I am convinced that there&#039;s a workaround that serves the same function as typing an object to an interface instead of an implementation in PHP, but I just haven&#039;t found it yet. In the original post I noted Matt Zandstra&#039;s code structure:
&lt;pre lang=&quot;actionscript&quot;&gt;
function __construct($propertyA, Strategy $strategy)
{
	$this-&gt;propertyA =$propertyA;
	$this-&gt;strategyProp = $strategy;
}
&lt;/pre&gt;

Where &quot;Strategy&quot; is an interface in the Strategy pattern. This may be how to program to an interface instead of an implementation in PHP. I&#039;m just not sure though because I&#039;m more of a weekend PHP programmer than a hard core one like many.

So if you can help us out on this key design pattern principle as it applies to PHP, I&#039;d be most grateful. Maybe &lt;a href=&quot;http://books.google.com/books?id=qVLjFk_4zVYC&amp;pg=PA137&amp;lpg=PA137&amp;dq=Matt+Zandstra+php+program+to+an+interface+not+an+implementation&amp;source=bl&amp;ots=fObQikZQPt&amp;sig=VGYyKJfCh9bSpyxHNrsufmTlPe4&amp;hl=en&amp;ei=9-koSrXTEISNtgeR17GpCA&amp;sa=X&amp;oi=book_result&amp;ct=result&amp;resnum=1&quot; rel=&quot;nofollow&quot;&gt;Matt&#039;s explanation&lt;/a&gt; would make more sense to a PHP programmer than to an ActionScript 3.0 one!

Kindest regards,
Bill</description>
		<content:encoded><![CDATA[<p>Hi Daniel,</p>
<p>Thanks for the link. I looked at it, and while I did not come any closer to solving the riddle of how to code to an interface instead of an implementation in PHP, it&#8217;s a very good PHP site. One of the insights that I liked very much is Will Fitch&#8217;s observation that the Factory Pattern (I believe he actually meant Factory Method Pattern) can be used instead of the Singleton. I think that may be useful for those who want Singleton functionality but who do not like the Singleton&#8217;s problems (see <a href="http://www.as3dp.com/2008/11/26/we-don’t-need-no-stinkin’-singletons-why-to-avoid-the-singleton-pattern-in-actionscript-30-programming/" rel="nofollow">We Don&#8217;t Need No Stinkin&#8217; Singletons</a>).</p>
<p>I don&#8217;t mean to sound like I&#8217; being a purist (and certainly not a prig!) about OOP and Design Patterns. I want to be as inclusive as possible when it comes to OOP/DP. Rather, I&#8217;m looking for a way to use design patterns with PHP. I am convinced that there&#8217;s a workaround that serves the same function as typing an object to an interface instead of an implementation in PHP, but I just haven&#8217;t found it yet. In the original post I noted Matt Zandstra&#8217;s code structure:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p997code1'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p9971"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p997code1"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #66cc66;">&#40;</span>$propertyA, Strategy $strategy<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	$this-<span style="color: #66cc66;">&gt;</span>propertyA =$propertyA;
	$this-<span style="color: #66cc66;">&gt;</span>strategyProp = $strategy;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Where &#8220;Strategy&#8221; is an interface in the Strategy pattern. This may be how to program to an interface instead of an implementation in PHP. I&#8217;m just not sure though because I&#8217;m more of a weekend PHP programmer than a hard core one like many.</p>
<p>So if you can help us out on this key design pattern principle as it applies to PHP, I&#8217;d be most grateful. Maybe <a href="http://books.google.com/books?id=qVLjFk_4zVYC&#038;pg=PA137&#038;lpg=PA137&#038;dq=Matt+Zandstra+php+program+to+an+interface+not+an+implementation&#038;source=bl&#038;ots=fObQikZQPt&#038;sig=VGYyKJfCh9bSpyxHNrsufmTlPe4&#038;hl=en&#038;ei=9-koSrXTEISNtgeR17GpCA&#038;sa=X&#038;oi=book_result&#038;ct=result&#038;resnum=1" rel="nofollow">Matt&#8217;s explanation</a> would make more sense to a PHP programmer than to an ActionScript 3.0 one!</p>
<p>Kindest regards,<br />
Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel</title>
		<link>http://www.as3dp.com/2009/05/25/actionscript-30-and-php-5-doing-design-patterns/comment-page-1/#comment-2501</link>
		<dc:creator>Daniel</dc:creator>
		<pubDate>Thu, 04 Jun 2009 20:53:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=997#comment-2501</guid>
		<description>Bill,

You might want to check out http://www.phpfever.com/.  They have lots of PHP design pattern postings.  It may not be pure enough to meet your formal def, but I think it gets the benefits of design patterns.

Daniel</description>
		<content:encoded><![CDATA[<p>Bill,</p>
<p>You might want to check out <a href="http://www.phpfever.com/" rel="nofollow">http://www.phpfever.com/</a>.  They have lots of PHP design pattern postings.  It may not be pure enough to meet your formal def, but I think it gets the benefits of design patterns.</p>
<p>Daniel</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William B. Sanders</title>
		<link>http://www.as3dp.com/2009/05/25/actionscript-30-and-php-5-doing-design-patterns/comment-page-1/#comment-2500</link>
		<dc:creator>William B. Sanders</dc:creator>
		<pubDate>Thu, 04 Jun 2009 20:46:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=997#comment-2500</guid>
		<description>Hi Daniel,

Thank you for your comment--I&#039;m especially interested in how the PHP folks deal with &lt;em&gt;programming to an interface and not an implementation&lt;/em&gt; without using typed variables.

I think you hit the nail on the head in pointing out that you cannot make a non-typed language (such as PHP) do something that it is not intended to do. However, I find lots of PHP design patterns out there, but they all seem to be coding to an implementation and not an interface (abstract class or interface.) Since the first dictum of design patterns by GoF is to program to an interface instead of an implementation, I&#039;m curious how that might be done.

If you know any PHP coders who use design patterns, I&#039;d like to find out how they do that.

Thanks,
Bill</description>
		<content:encoded><![CDATA[<p>Hi Daniel,</p>
<p>Thank you for your comment&#8211;I&#8217;m especially interested in how the PHP folks deal with <em>programming to an interface and not an implementation</em> without using typed variables.</p>
<p>I think you hit the nail on the head in pointing out that you cannot make a non-typed language (such as PHP) do something that it is not intended to do. However, I find lots of PHP design patterns out there, but they all seem to be coding to an implementation and not an interface (abstract class or interface.) Since the first dictum of design patterns by GoF is to program to an interface instead of an implementation, I&#8217;m curious how that might be done.</p>
<p>If you know any PHP coders who use design patterns, I&#8217;d like to find out how they do that.</p>
<p>Thanks,<br />
Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel</title>
		<link>http://www.as3dp.com/2009/05/25/actionscript-30-and-php-5-doing-design-patterns/comment-page-1/#comment-2489</link>
		<dc:creator>Daniel</dc:creator>
		<pubDate>Tue, 02 Jun 2009 18:22:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=997#comment-2489</guid>
		<description>Interesting post.  I am a hard core PHP dev.  The flash designer in my company pointed me to this article.  I enjoyed reading it, and thought I would share a couple of thoughts.  First, be careful not to try a do something in a language that it is not intended.  PHP is not a strict typed language.  If you design pattern is built on the concept of being strict typed, then you probably will need to pick a new pattern.

Second, if you do need to check the type of item passed you can accomplish it by putting a check on the setting of the property with the PHP magic getter and setter methods.  These are methods called by PHP when you try to access an object&#039;s property outside of the object.  For example:

{$key} = $value;
  }
?&gt;</description>
		<content:encoded><![CDATA[<p>Interesting post.  I am a hard core PHP dev.  The flash designer in my company pointed me to this article.  I enjoyed reading it, and thought I would share a couple of thoughts.  First, be careful not to try a do something in a language that it is not intended.  PHP is not a strict typed language.  If you design pattern is built on the concept of being strict typed, then you probably will need to pick a new pattern.</p>
<p>Second, if you do need to check the type of item passed you can accomplish it by putting a check on the setting of the property with the PHP magic getter and setter methods.  These are methods called by PHP when you try to access an object&#8217;s property outside of the object.  For example:</p>
<p>{$key} = $value;<br />
  }<br />
?&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William B. Sanders</title>
		<link>http://www.as3dp.com/2009/05/25/actionscript-30-and-php-5-doing-design-patterns/comment-page-1/#comment-2420</link>
		<dc:creator>William B. Sanders</dc:creator>
		<pubDate>Tue, 26 May 2009 20:18:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=997#comment-2420</guid>
		<description>Hi Chandima,

I&#039;m sort of a Notepad programmer when it comes to PHP. I&#039;m going to play around with the &lt;em&gt;instanceof&lt;/em&gt; check. By the way, if you put in:

&lt;?php .... and....?&gt; when using the plugin with PHP, you get the color coding:

Like this:
&lt;pre lang=&quot;php&quot;&gt;
&lt;?php
function makeSureMyParamsAreGood( MyClass $obj )
{
    // ...
}
?&gt;
&lt;/pre&gt;

Cool, huh?

Cheers,
Bill</description>
		<content:encoded><![CDATA[<p>Hi Chandima,</p>
<p>I&#8217;m sort of a Notepad programmer when it comes to PHP. I&#8217;m going to play around with the <em>instanceof</em> check. By the way, if you put in:</p>
<p>< ?php .... and....?> when using the plugin with PHP, you get the color coding:</p>
<p>Like this:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p997code2'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p9972"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p997code2"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> makeSureMyParamsAreGood<span style="color: #009900;">&#40;</span> MyClass <span style="color: #000088;">$obj</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// ...</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Cool, huh?</p>
<p>Cheers,<br />
Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chandima Cumaranatunge</title>
		<link>http://www.as3dp.com/2009/05/25/actionscript-30-and-php-5-doing-design-patterns/comment-page-1/#comment-2418</link>
		<dc:creator>Chandima Cumaranatunge</dc:creator>
		<pubDate>Tue, 26 May 2009 17:22:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=997#comment-2418</guid>
		<description>Bill, you got me very interested in this as I&#039;ve been developing some Wordpress plugins recently. Wordpress runs on a PHP-MySQL backend. AFter developing a couple of plugins and themes, I realized that a lot of time was spent trying to locate errors. 

Being a dynamically typed language, PHP errors only appear at run-time. Many errors were type mismatches that would be easily caught in a statically typed language  during compile-time. &quot;Trying&quot; is the key here as a PHP type error manifests itself somewhere other than where the culprit resides. One has to backtrace the call stack to isolate the type error.

I actually ended up writing a logger plugin that enabled me to pretty print PHP objects onto the browser console just to help with debugging. However, logging variables is a poor substitute for strong typing.

A type check on function parameters would be a big help indeed. I went back to my favorite PHP 5 book - &quot;PHP 5 Power Programming&quot; by Gutmans, Bakken, and Rethans. Lo and behold, PHP 5 does have a built-in type check for function parameters.

&lt;pre lang=&quot;php&quot;&gt;
function makeSureMyParamsAreGood( MyClass $obj )
{
    // ...
}
&lt;/pre&gt;

When the above function is called, PHP will do an &lt;em&gt;instanceof&lt;/em&gt; check to make sure that the &lt;code&gt;$obj&lt;/code&gt; is of type &lt;code&gt;MyClass&lt;/code&gt;. If not, it will throw an error. The cool thing is that the &lt;em&gt;instanceof&lt;/em&gt; check returns true even if &lt;code&gt;$obj&lt;/code&gt; is an instance of a &lt;em&gt;subclass&lt;/em&gt; of &lt;code&gt;MyClass&lt;/code&gt;. 

It would be nice to have a PHP IDE that does type checking. Wonder if Zend Studio does this?</description>
		<content:encoded><![CDATA[<p>Bill, you got me very interested in this as I&#8217;ve been developing some Wordpress plugins recently. Wordpress runs on a PHP-MySQL backend. AFter developing a couple of plugins and themes, I realized that a lot of time was spent trying to locate errors. </p>
<p>Being a dynamically typed language, PHP errors only appear at run-time. Many errors were type mismatches that would be easily caught in a statically typed language  during compile-time. &#8220;Trying&#8221; is the key here as a PHP type error manifests itself somewhere other than where the culprit resides. One has to backtrace the call stack to isolate the type error.</p>
<p>I actually ended up writing a logger plugin that enabled me to pretty print PHP objects onto the browser console just to help with debugging. However, logging variables is a poor substitute for strong typing.</p>
<p>A type check on function parameters would be a big help indeed. I went back to my favorite PHP 5 book &#8211; &#8220;PHP 5 Power Programming&#8221; by Gutmans, Bakken, and Rethans. Lo and behold, PHP 5 does have a built-in type check for function parameters.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p997code3'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p9973"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p997code3"><pre class="php" style="font-family:monospace;">function makeSureMyParamsAreGood( MyClass $obj )
{
    // ...
}</pre></td></tr></table></div>

<p>When the above function is called, PHP will do an <em>instanceof</em> check to make sure that the <code>$obj</code> is of type <code>MyClass</code>. If not, it will throw an error. The cool thing is that the <em>instanceof</em> check returns true even if <code>$obj</code> is an instance of a <em>subclass</em> of <code>MyClass</code>. </p>
<p>It would be nice to have a PHP IDE that does type checking. Wonder if Zend Studio does this?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://www.as3dp.com/2009/05/25/actionscript-30-and-php-5-doing-design-patterns/comment-page-1/#comment-2416</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Tue, 26 May 2009 16:37:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=997#comment-2416</guid>
		<description>Okay great.  Thank you for getting back to me so quickly.  That is a great plugin.</description>
		<content:encoded><![CDATA[<p>Okay great.  Thank you for getting back to me so quickly.  That is a great plugin.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chandima Cumaranatunge</title>
		<link>http://www.as3dp.com/2009/05/25/actionscript-30-and-php-5-doing-design-patterns/comment-page-1/#comment-2415</link>
		<dc:creator>Chandima Cumaranatunge</dc:creator>
		<pubDate>Tue, 26 May 2009 16:15:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=997#comment-2415</guid>
		<description>Hi Steve, we use the WP-CODEBOX Plugin for code formatting. Download from:

http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/</description>
		<content:encoded><![CDATA[<p>Hi Steve, we use the WP-CODEBOX Plugin for code formatting. Download from:</p>
<p><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/" rel="nofollow">http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://www.as3dp.com/2009/05/25/actionscript-30-and-php-5-doing-design-patterns/comment-page-1/#comment-2414</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Tue, 26 May 2009 15:42:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=997#comment-2414</guid>
		<description>I really like code reference that you use on this site.  What is it that you use or where can I find a snippet window like the one you have listed on the page to reference code?

Great Blog!</description>
		<content:encoded><![CDATA[<p>I really like code reference that you use on this site.  What is it that you use or where can I find a snippet window like the one you have listed on the page to reference code?</p>
<p>Great Blog!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William B. Sanders</title>
		<link>http://www.as3dp.com/2009/05/25/actionscript-30-and-php-5-doing-design-patterns/comment-page-1/#comment-2410</link>
		<dc:creator>William B. Sanders</dc:creator>
		<pubDate>Tue, 26 May 2009 12:34:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=997#comment-2410</guid>
		<description>Hi David,

Thanks for the tip. I&#039;ve heard about the Zend PHP framework and took a quick look at it. However, I don&#039;t remember seeing instances typed to an interface. Because abstract classes cannot be instantiated, I have not yet solved the riddle of how to program to an interface instead of an implementation in PHP.

Zend PHP sounds like a good place to dig. I&#039;ll start shoveling!

Kindest regards,
Bill</description>
		<content:encoded><![CDATA[<p>Hi David,</p>
<p>Thanks for the tip. I&#8217;ve heard about the Zend PHP framework and took a quick look at it. However, I don&#8217;t remember seeing instances typed to an interface. Because abstract classes cannot be instantiated, I have not yet solved the riddle of how to program to an interface instead of an implementation in PHP.</p>
<p>Zend PHP sounds like a good place to dig. I&#8217;ll start shoveling!</p>
<p>Kindest regards,<br />
Bill</p>
]]></content:encoded>
	</item>
</channel>
</rss>
