PHP 注册树模式

hero();

//	注册树
class Register
{
	protected static $objects;
	
	public static function set($alias,$object)
	{
		self::$objects[$alias] = $object;
	}
	
	public static function get($alias)
	{
		return self::$objects[$alias];
	}
	
	public static function _unset($alias)
	{
		unset(self::$objects[$alias]);
	}
}

Register::set('hero1',Factory::toYou(1));
Register::set('hero2',Factory::toYou(2));
Register::set('hero3',Factory::toYou(3));
Register::set('hero4',Factory::toYou(4));
Register::set('hero5',Factory::toYou(5));

$hero1 = Register::get('hero1');
$hero2 = Register::get('hero2');
$hero3 = Register::get('hero3');
$hero4 = Register::get('hero4');
$hero5 = Register::get('hero5');

echo $hero1->hero();
echo $hero2->hero();
echo $hero3->hero();
echo $hero4->hero();
echo $hero5->hero();

你可能感兴趣的:(PHP 注册树模式)