2010年1月19日星期二

Re: [fw-mvc] Re: [fw-general] Bootstrap Resource usage in model - best practice advice please

> Zend_Registry uses Martin Fowler's Registry pattern. Not singleton.

Even if it does, it still follows the Singleton pattern, too. Or how is
the Zend_Registry instance accessed?

> No, it's not. Passing object by reference doesn't mean singleton.

Ok. But the point is, that a Singleton pattern is mimicked with the
example that was previously made, i.e.

class Default_Model_Base_Abstract
{

protected $_cacheKey = 'opamama';

protected function _getCacheInstance()
{
if (Zend_Registry::isRegistered($this->_cacheKey)) {
$cache = Zend_Registry::get('cache');
} else {
$cache = Zend_Cache::factory();
Zend_Registry::set($this->_cacheKey, $cache);
}
return $cache;
}

}

> You're wrong. As you know, objects since PHP5 are passed by reference.
> So you will have most probably only one object instance, referenced to
> each model, except you prefer otherwise. And that's the way I would prefer.

So, how are you going to access and store your cache instance?


Best regards,

Andreas

没有评论: