Re: patterns in SPL and PEAR
| From: | Jeff Moore | Date: | Thu, 21 Apr 2005 05:05:40 +0000 |
| Subject: | Re: patterns in SPL and PEAR | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-37314@lists.php.net to get a copy of this message | ||
On Apr 19, 2005, at 6:47 AM, Lukas Smith wrote:
ext/SPL Observer: http://www.php.net/~helly/php/ext/spl/interfaceObserver.html ext/SPL Subject: http://www.php.net/~helly/php/ext/spl/interfaceSubject.htmlHello, I think the GoF interfaces are good for illustrating the observer pattern, but perhaps C# delegates are a more a appropriate paradigm for dynamically typed PHP. As you might know, delegates are really just first class object versions of PHP's callback pseudo type. Observer (events) can be implemented with delegates instead of interfaces. Here are a couple of good overviews of delegates: http://msdn.microsoft.com/msdnmag/issues/01/04/net/default.aspx http://www.ondotnet.com/pub/a/dotnet/2002/11/04/delegates.htm Here some references specifically comparing the delegate style versus the interface style: http://msdn.microsoft.com/vjsharp/productinfo/visualj/visualj6/technical/articles/general/truth/default.aspx http://java.sun.com/docs/white/delegates.html http://www.onjava.com/pub/a/onjava/2003/05/21/delegates.html Note that neither sun, nor Microsoft are arguing that interfaces alone are sufficient, but instead if delegates or inner classes are better. Since PHP is not likely to get inner classes soon and already has callbacks (although as a second class citizen), I think delegates may be a better model for PHP to emulate. Here is a PHP implementation of delegates and events (complicated a bit by supporting PHP 4 and lazy loading): http://cvs.sourceforge.net/viewcvs.py/wact/wact/framework/util/delegate.inc.php?view=auto And finally, some blog entries delving into the internal implementation of delegates and covering these previous issues: http://blog.monstuff.com/archives/000037.html http://blog.monstuff.com/archives/000038.html http://blog.monstuff.com/archives/000040.html My apologies if this is not an appropriate post for this forum. Regards, Jeff