05-05-2008, 10:24 PM
|
#7 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
Quote:
Originally Posted by xenon
|
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($szClass, self::$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;
}
|
|
|
|