Not suitable for two reasons:
1) the check is difficult (instanceof, class_implements(), class_parents()
and is_subclass_of() need objects)
2) every model would have to implement getInstance themselves, that's
stupid. This will be provided by SingletonModel:
abstract class SingletonModel extends Model
{
        protected static $instance = null;
        private function __construct()
        {
        }
        public static function getInstance($className)
        {
                if(self::$instance === null)
                        self::$instance = new $className();
                return self::$instance;
        }
}

- David


> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
> Behalf Of Rob Halff
> Sent: Monday, June 27, 2005 4:06 PM
> To: Agavi Development
> Subject: RE: [agavi-dev] Singleton Models
> 
> How about class MyCustomModel extends Model implements Singleton ?
> 
> Greetings,
> 
> Rob Halff.
> 
> 
> Op ma, 27-06-2005 te 13:15 +0200, schreef David Zülke:
> > Yeah, correct, there'll be a new class "SingletonModel". If you want to
> > create a new model that works as a singleton, you just do
> >
> > class MyCustomModel extends SingletonModel
> >
> > instead of
> >
> > class MyCustomModel extends Model
> >
> >
> > - David
> >
> > > -----Original Message-----
> > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> On
> > > Behalf Of graeme
> > > Sent: Monday, June 27, 2005 4:52 AM
> > > To: Agavi Development
> > > Subject: Re: [agavi-dev] Singleton Models
> > >
> > > By option #1 I understand that you mean
> > > SingletonModel extends Model
> > >
> > > that approach gets my vote (every time):
> > > To me it is the way we should use OOP extending the functionality
> > > through new classes.
> > >
> > > By the way I'm working on a script that will create xmi from the
> > > framework so that we can have some UML models of the framework.
> > > Hopefully I'll have this thrashed our by the end of the week.
> > >
> > > graeme.
> > >
> > >
> > > David Zülke wrote:
> > >
> > > >Cheers folks,
> > > >
> > > >Agavi's Model implementation currently lacks support for Singletons.
> From
> > > >what I can see, there are three ways to implement that:
> > > >
> > > >1) if you want your Model to be Singleton, extend SingletonModel
> instead
> > > of
> > > >Model. The Controller will automagically call getInstance() when he
> > > stumbles
> > > >over a class that is a singleton. This method is guaranteed to work,
> as I
> > > >already implemented it
> > > >
> > > >2) have a separate method, Comtroller::get(Global)SingletonModel().
> IMO,
> > > >this sucks big time
> > > >
> > > >3) change Controller::get(Global)Model() to accept a third parameter
> > > which
> > > >defines the method that will be used to fetch an instance (i.e.
> > > $singleton =
> > > >Controller::getGlobalModel('whatever', 'getInstance);). This
> obviously
> > > >sucks, too, as we'll be running into trouble when we add more
> parameters
> > > to
> > > >those methods (for example when passing parameters, this is currently
> in
> > > >discussion IIRC).
> > > >
> > > >4) do #3, but use an array as the only parameter instead: $singleton
> =
> > > >Controller::getModel('blahmodule', array('ModelName',
> 'getInstance')); -
> > > >sucks as well if you ask me
> > > >
> > > >I opt for method #1. Will create a branch soon where this is
> implemented,
> > > >but I wanted to chime in and ask for opinions before I go ahead and
> start
> > > >working. So... objections, anyone?
> > > >
> > > >- David
> > > >
> > > >
> > > >_______________________________________________
> > > >agavi-dev mailing list
> > > >[email protected]
> > > >http://labworkz.com/cgi-bin/mailman/listinfo/agavi-dev
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> > > _______________________________________________
> > > agavi-dev mailing list
> > > [email protected]
> > > http://labworkz.com/cgi-bin/mailman/listinfo/agavi-dev
> >
> >
> >
> > _______________________________________________
> > agavi-dev mailing list
> > [email protected]
> > http://labworkz.com/cgi-bin/mailman/listinfo/agavi-dev
> --
> Rob Halff <[EMAIL PROTECTED]>
> 
> _______________________________________________
> agavi-dev mailing list
> [email protected]
> http://labworkz.com/cgi-bin/mailman/listinfo/agavi-dev



_______________________________________________
agavi-dev mailing list
[email protected]
http://labworkz.com/cgi-bin/mailman/listinfo/agavi-dev

Reply via email to