[EMAIL PROTECTED] wrote:
Andrey Hristov <[EMAIL PROTECTED]> writes:
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:
Yes, Pool. I just said that it is Singleton for multiple objects which
in fact is pool.
One 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.
There 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.
Derrell
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:)
Andrey
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php