Re: Re: OOP question

From: Date: Wed, 31 Aug 2005 13:41:38 +0000
Subject: Re: Re: OOP question
References: 1 2 3 4 5 6 7 8  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-39657@lists.php.net to get a copy of this message
Lukas Smith wrote:
Ammar Ibrahim wrote:
Lukas Smith wrote:
Ammar Ibrahim wrote:
I was under the impression a Singleton always implied a Factory.
Not really :) Thanks for the tip, I will check the code
So "normally" a Singleton should return null if no instance if the given object was created yet? Sounds fairly impractical. I think some of the Singleton implementations in PEAR even go so far as to completly ignore instances created directly or via a factory and since the static var they store the instance in as scoped inside the singleton method. regards, Lukas
No this is not what I meant. Simply a singleton can be created from a standalone class( one that does not implement a factory ). But having a factory that returns a singleton object can get quite complex, e.g. Having a single object from a Type $a =& Log::factory( 'Database' ); $b =& Log::factory( 'LDAP' ); $c =& Log::factory( 'Database' ); So the behaviour would be that $a & $c are the same object, but $c isn't. I don't know if this is a standard design pattern, as it implements singleton( Only for the same factory driver ).
Well MDB2::singleton() checks if the dsn is the same and only returns the first instance that uses the same DSN. This is done by putting all created instances into a global array that singleton() iterates over. regards, Lukas This is exactly what I meant :) Thanks


« previous php.pear.dev (#39657) next »