> On 7/2/05, David Zülke <[EMAIL PROTECTED]> wrote:
> > You're wrong. Read an OO programming book. There won't be a new instance
> of
> > GoodSingletonModel because the instances array sits in SingletonModel.
> > BadSingletonModel only overwrites getInstance and $instance only for
> itself.
>
> Illustrate it in tests, they're cheaper than books.
>
> 1. Why are do I need to tell MyCrazySingleton's getInstance what class
> I want an instance of?
Because self:: will reference "SingletonModel". No way to determine which
class calls the parent getInstance().
I know this is not perfect, but there's no way around it. It's because of
the way PHP works. People complained on php-internals even back in beta
times, but "those in power" didn't give a shit, as usual.
> 2. Why does MyCrazySingleton have instances of other singletons?
SingletonModel::$instances is static, so it doesn't really "have" the
instances (although they're accessible from everywhere)
> 3. The singletonmodel's tests should be in a file on their own rather
> than interspersed with model's tests so that it's clear what we're
> testing.
Well... okay
> 4. I think it would be a lot cleaner if you used is_subclass_of() to
> check the method of instantiating to use
>
> if (is_subclass_of($class, 'SingletonModel')) {
> $model = $class::getInstance();
> } else {
> $model = new $class;
> }
> $model->initialize($this->context);
> return $model;
Of course it would. But that doesn't work with PHP < 5.0.3. In 99,997% of
situations, get_parent_class() will only be called once.
> I'm seriously getting in the car now..
See you on Tuesday,
- David
_______________________________________________
agavi-dev mailing list
[email protected]
http://labworkz.com/cgi-bin/mailman/listinfo/agavi-dev