Thread: New approach
View Single Post
Old 05-05-2008, 10:24 PM   #7 (permalink)
delayedinsanity
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Quote:
Originally Posted by xenon View Post
I'd go for the Registry pattern. Registry pattern
Isn't that just another form of the singleton? It's basically what I'm doing, based off of what I learned about the singleton pattern - however instead of including a getInstance() function inside of all my classes, I simple built a superclass that lets me grab whatever instance I want, and stores it all in a static array.

It looks a lot like yours, except I only have two methods I use, loadParent, and load, which looks like;

PHP Code:
static function &load ($szModule$szClass$szArgs=null) {

    
$szFilename "{$szModule}.{$szClass}.php";
    
$szClass    "kePhoto_{$szModule}_{$szClass}";

    if (
array_key_exists($szClassself::$m_aInstance)) {
        
$pInstance =& self::$m_aInstance[$szClass];

    } else {

        if (!
class_exists($szClass)) {
            
$szPath PATH_TO_LIB."/{$szFilename}";
            include(
$szPath);
        }

        
self::$m_aInstance[$szClass] =  new $szClass($szArgs);
        
$pInstance               =& self::$m_aInstance[$szClass];
    }
    
    return 
$pInstance;
            

delayedinsanity is offline  
Reply With Quote