Re: patterns in SPL and PEAR

From: Date: Thu, 21 Apr 2005 07:35:23 +0000
Subject: Re: patterns in SPL and PEAR
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-37316@lists.php.net to get a copy of this message
Jeff Moore wrote: >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. You can have a look at the packages Lukas posted : PEAR::Event_Dispatcher: http://pear.php.net/package/Event_Dispatcher PEAR::PEAR_Delegator: http://pear.php.net/package/PEAR_Delegator Those two are based on Objective-C and Apple Cocoa Framework, not Microsoft C#. It's funny how your articles give the wrong impression that Microsoft discovered the concepts :) Some other links to compensate yours: Notifications: <http://developer.apple.com/documentation/Cocoa/Conceptual/ CommunicateWithObjects/Articles/Notifications.html> Delegation: <http://developer.apple.com/documentation/Cocoa/Conceptual/ CommunicateWithObjects/Articles/Delegates.html> Cheers, Bertrand

« previous php.pear.dev (#37316) next »