0
对于一个项目我有一些对象,一种方法是加载父实体。所以我打电话给我这样的方法: $ this-> getDetails() - > getEntity();是否需要缓存对象?
所以getEntity的代码是:
public function getEntity()
{
if (isset($this->entity)) {
return $this->entity;
} else {
$mapper = new Crm_Mapper_Entity();
return $this->entity = $mapper->find($this->customerId);
}
}
是有必要的实体加载到属性?因为当我想把它加载到另一个地方时,它不应该再次调用映射器。
或者当它被加载时,对象已经在内存中,我不需要将它放入属性中?
感谢
不要使用Singleton模式。 http://misko.hevery.com/2008/08/17/singletons-are-pathological-liars/ – dynamic 2011-05-31 14:24:33