2010年1月17日星期日

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

> This implies that you have multiple cache instances.
> If you don't, singleton is the best approach.

Ok. It might depend on business logic. But singleton is only for one thing good: it ensures, that there will be only one instance of this object in a life cycle. 

So with singleton you would exclude possibility to bypass other caching objects. But non-singleton solution doesn't mean that you will have multiple instances.

Singleton makes also unit testing more difficult.

In other words, I don't see the benefit of singleton pattern, only loosing possibility to have multiple instances if its needed, and making it more difficult for unit testing
 

--
Regards,
Vladas Diržys


On Sun, Jan 17, 2010 at 17:33, Andreas Möller <localheinz@l8m.de> wrote:
Don't think so.


Singleton only if you have base model class, and/or only for
default cache (BaseModel::setDefaultCache(),
BaseModel::getDefaultCache()).

This implies that you have multiple cache instances.
If you don't, singleton is the best approach.

If you do, your cache instances will vary in their options (e.g., type of backend, lifetime). If so, you'd at best still have a method that returns you the instance for the specified options, and internally, the method might check whether an instance with this gestalt has already been created, otherwise create it.

This would be some sort of multiton pattern, wouldn't it?

Otherwise singleton is wrong approach.

And yes, this would even make sense if you didn't have a base model class.


Best regards,

Andreas


没有评论: