Created
October 15, 2013 14:46
-
-
Save jooohn/6992726 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// getSingletonInstance は static メソッドになる? | |
class Module | |
{ | |
use TSingleton; | |
static $FUNC_NAME_SINGLETON = 'singleton'; | |
static function singleton() | |
{ | |
static $instance = null; | |
if (is_null($instance)) { | |
$instance = new static(); | |
} | |
return $instance; | |
} | |
} | |
class ModuleFactory | |
{ | |
static function getModule($name) | |
{ | |
static $instances = []; | |
if (!array_key_exists($name, $instances) { | |
$instances[$name] = Module::getSingletonInstance(); | |
} | |
return $instances[$name]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ModuleFactoryのほうはstatic $instances不要ですね