When you see a method called getInstance(), is it assumed to be a singleton
class. I don't think non singleton classes use or need to have a method
called getInstance(). What are you trying to achieve with a static function
that returns a new instance of the class that you can not or don't want to
achieve by just creating a new instance as in "$instance = new SomeClass;" ?


On Tue, Jul 21, 2009 at 10:38 PM, Marko Korhonen <
[email protected]> wrote:

>
> Hi,
>
> Here's my original method:
> public static function getInstance()
>    {
>        if (null === self::$_instance) {
>            self::$_instance = new self();
>        }
>
>        return self::$_instance;
>    }
>
> and I changed it to:
>
> public static function getInstance()
>    {
>        return new self();
>    }
>
> Maybe the method name still implies to singleton?
>
> Marko
>
>
> Peter Warnock-2 wrote:
> >
> > On Tue, Jul 21, 2009 at 10:53 AM, Marko Korhonen <
> > [email protected]> wrote:
> >
> >>
> >> Thanks fo everybody for the great comments!
> >>
> >> I decided to change my getInstance() method so it just
> >> created new instance of the class and returns it (giving up on singleton
> >> on this case).
> >>
> >> So if I have static call:
> >> $model = Comment_Model_Comment::getInstance();
> >> it's the same if I would write:
> >> $model = new Comment_Model_Comment();
> >>
> >> Only difference being that I can call directly some methods like:
> >> $comments = Comment_Model_Comment::getInstance()->getAll();
> >>
> >> Any considerations to this one?
> >>
> >> getInstance implies it is a Singleton. You are describing a factory
> >> method.
> >
> > - pw
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Models-as-Singletons-tp24575704p24595370.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
>

Reply via email to