Re: Re: Function Cache
| From: | Kristian Köhntopp | Date: | Mon, 11 Dec 2000 11:33:02 +0000 |
| Subject: | Re: Re: Function Cache | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.dev php.pear |
| Request: | Send a blank email to php-dev+get-40827@lists.php.net to get a copy of this message | ||
"Stig S. Bakken" wrote:
> We're talking about different things. Your "autoload" is not
> really for autoloading anything (AFAIK you can't add methods
> to objects), but for catching "undefined function" errors.
Yep. That is why I was calling it _delegate() at first. Using
such a function, you can define a delegate object for any object,
just as I did with my example
class generic_proxy {
var $proxy_reference;
function _delegate($function_name) {
// whatever the correct syntax is...
($this->proxy_reference)->$function_name(func_get_args());
}
}
You can then try to forward unknown method calls to
your delegate object and see if it knows how to handle
them. If it does, you act as the delegate object would
have acted, presenting yourself to the outside as if you
handled that call yourself.
Sterling named this functionality AUTOLOAD, I believe
in reference to Perl. I learned about delegate objects
in Objective-C, where this method was used doing several
really interesting things.
One application is similar to our caching scenario, where
the Objective-C people needed a generic (Remote Procedure
Call-) Proxy class which can stand in for any other class,
just like our generic_proxy does. In fact they went one step
further in some other places, where the Proxy class used
a method named pose_as($classname) to pose as the actual
class it stood in for.
Another application for delegate objects was to save yourself
dozens of subclasses: Usually you had to handle application
specific methods in many Window, View, Controller instances
as well as to handle specific methods in Application. What you
usually did for small applications was to create a single
instance of some Model, and set the Model instance as a delegate
for everything.
This allowed you to handle all kinds of redraw events, menu
activation things and everything else in your model instance,
with no need to subclass Window, Application an so on. Basically,
you insert just one additional class into the system and reroute
all undefined events to that class. This works very well for
small applications, can be transparently retrofitted if your
application grows and makes for a very simple class hierarchy.
Kristian
--
Kristian Köhntopp, NetUSE AG Siemenswall, D-24107 Kiel
Tel: +49 431 386 436 00, Fax: +49 431 386 435 99
Using PHP3? See our web development library at http://phplib.netuse.de/