Re: patterns in SPL and PEAR

From: Date: Thu, 21 Apr 2005 16:55:27 +0000
Subject: Re: patterns in SPL and PEAR
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-37321@lists.php.net to get a copy of this message
On Apr 21, 2005, at 3:35 AM, Bertrand Mansion wrote:
You can have a look at the packages Lukas posted : ...
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 :)
I was a Delphi programmer for about 5 years and I learned to respect the language design skills of Anders Hejlsberg. No, Microsoft didn't invent the Delegate/callback. However, they did implement their solution after Java and after Objective-C, and thus were able to learn from their problems. What C# did that these earlier languages didn't is make the callback a first class language feature. Microsoft probably didn't invent that either, but they do have good and well explained implementation of it.
Some other links to compensate yours: Notifications: <http://developer.apple.com/documentation/Cocoa/Conceptual/ CommunicateWithObjects/Articles/Notifications.html>
I am familiar with this and I think Cocoa and Objective-C are excellent role models for PHP. Better in many ways than Java, C and C++. And this link re-enforces my point which is that callbacks make more sense than interfaces in a dynamic language like PHP. The Cocoa Notification Center is implemented with callbacks not interfaces.
PEAR::Event_Dispatcher: http://pear.php.net/package/Event_Dispatcher
And this implementation uses callbacks and not interfaces. Again, my point is that callbacks are the more natural and flexible was to specify observers in PHP than an interface such as this:
http://www.php.net/~helly/php/ext/spl/interfaceObserver.html
However, in implementing the observer pattern, that still leaves the task of registering observers. I also think this interface is too limited for general purpose use:
http://www.php.net/~helly/php/ext/spl/interfaceSubject.html
Java accomplishes the same thing with a naming convention: (works fine in PHP) registerXXXListener C# does it by making an event a first class language feature, another kind of class member. (unlikely to happen anytime soon in PHP) Objective-C (and Event_Dispatcher) do it with a separate object. (works fine in PHP.)
Delegation: <http://developer.apple.com/documentation/Cocoa/Conceptual/ CommunicateWithObjects/Articles/Delegates.html>
Just to be clear, this is a different concept than the C# delegates. Every good name is overloaded. :) Regards, Jeff

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