Marko Korhonen a écrit :
Ok,

I might live with that. So what are the main pros using singletons?

- Is there performance gain or memory savings or something like that?
- Code syntax benefits?
- Something else?


You don't use singleton for performance or whatever, you use singleton because that's what your buisness model tell you. For more information you can look at the GOF book page 127.


Only thing I really understand that it gets always the same instance of the
class
and does not create new ones.

br, Marko


Matthew Weier O'Phinney-3 wrote:
-- Marko Korhonen <[email protected]> wrote
(on Monday, 20 July 2009, 12:06 PM -0700):
I made my Model classes singletons and I'm wondering if there is any
major
cons in this solution.
One major one: Testing.

I've had to do a lot of testing against singletons, and it's simply not
worth it. It requires hacks for resetting state, and when you have a
test suite where these objects may be used in a number of different
suites, state becomes a tricky proposition.

Here's my setup from one on the modules:
Comment_Model_Comment (Model Comment from Comment module, Singleton)
Comment_Model_DbTable_Comment (Zend_Db_Table extended class)
Comment_Model_DbTable_Rowset_Comment (Zend_Db_Table_Rowset extended
class)
Comment_Model_DbTable_Row_Comment (Zend_Db_Table_Row extended class)

So I made my Model class as singleton becouse it does not represent
individual comments.
It's just one class knowing what to do with comments.

I tried to avoid having too many instances of this model class for vain.

Any comments or questions ?
--
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/





--
-- Mathieu Suen
--

Reply via email to