Re: new overloading feature?
| From: | Andrey Hristov | Date: | Fri, 05 Nov 2004 17:14:49 +0000 |
| Subject: | Re: new overloading feature? | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-13734@lists.php.net to get a copy of this message | ||
Derrell.Lipman@UnwiredUniverse.com wrote:
Andrey Hristov <php@hristov.com> writes:Yes, Pool. I just said that it is Singleton for multiple objects which in fact is pool.Why not using Singleton for multiple objects with getInstance() ?Yeah, it's not quite a Singleton pattern. I've seen references to what I'm talking about as a Pool pattern. That's basically what I described here:
The thing I find nice in the current way of implementing it with getInstance() and a static class variable is that it is like it is defined in GoF. People can easily understand what's going on. Otherwise it is too much of magic to me:) AndreyThere are absolutely ways to do this purely at the application level. It just seems that it'd be a really clean, easy to program, easy to understand methodology to pass the key value to the request for a new instance, and get back either a new instance, or a previously existing one with that key value. In fact, the proposed __new() feature could provide an automatic Singleton capability without the caller needing to worry about (or even know) that it's dealing with a Singleton. The class defines a __new() function that always returns its one and only instance (instantiating it the very first time), and the application can always use 'new' without worrying about the internal implementation. DerrellOne could certainly call a function which searched for the key value and only instantiated a new object if the existing one was not found, but this seems cleaner.