Re: drop singletons in favor of static calls

Manuel Holtgrewe <[email protected]> Wed, 02 Mar 2005 23:40:30 +0100
Newsgroups gmane.comp.lib.binarycloud.devel
Message-ID <[email protected]>
Okay, grep gives me:

debug/Debug.php:    function &getInstance() {
env/Client.php:    function &getInstance() {
env/Env.php:    function &getInstance() {
env/Request.php:    function &getInstance() {
env/Session.php:    function &getInstance() {
env/URI.php:    function &getInstance() {
event/Event.php:    function &getInstance() {
init/BcErrorHandler.php:    // {{{ function &getInstance()
init/BcErrorHandler.php:    function &getInstance() {
init/Project.php:    function &getInstance() {
log/Log.php:    function &getInstance() {
node/Resources.php:    function &getInstance() {
node/Template.php:    function &getInstance() {
unit_test/ErrorHandler.php:    function &getInstance() {

So replacing all this would lead to Log::entry(), Client::sendHeader() 
etc. calls.

In OOP, you use the singleton pattern to provide utilty things that have 
a state - like you would have in Conf, Log (where log output is stored) 
etc. While it is possible to use static calls here, you'd need not 
static versions of those methods to operate on the instance:

   // in Conf
   function get($name) {
     static $conf == null;
     if ($conf === null) $conf =& Conf::getInstance();
     return $conf->getNonStatic($name);
   }

And I consider that as bad design. I'd agree to use static calls 
everywhere you have no state - but where would that be, not much but 
Env, I guess. So even Log would become a singleton again.


*m
_______________________________________________
dev mailing list
dev-PnctHDZWAvB/Cz2I37pSEPZ4XP/[email protected]
http://lists.binarycloud.com/mailman/listinfo/dev