Skip to content

Instantly share code, notes, and snippets.

@jooohn
Created October 15, 2013 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jooohn/6992726 to your computer and use it in GitHub Desktop.
Save jooohn/6992726 to your computer and use it in GitHub Desktop.
// 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];
}
}
@jooohn
Copy link
Author

jooohn commented Oct 15, 2013

ModuleFactoryのほうはstatic $instances不要ですね

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment