调用:
define("BASEDIR",__DIR__);
include BASEDIR.'/IMooc/Loader.php';
spl_autoload_register("\\IMooc\\Loader::autoload");
IMooc\Object::test();
App\Controller\Home\Index::test();
\IMooc\Factory::createDatabase();
$object =\IMooc\Register::get("db1");
var_dump($object);
define("BASEDIR",__DIR__);
include BASEDIR.'/IMooc/Loader.php';
spl_autoload_register("\\IMooc\\Loader::autoload");
IMooc\Object::test();
App\Controller\Home\Index::test();
\IMooc\Factory::createDatabase();
$object =\IMooc\Register::get("db1");
var_dump($object);
2016-03-03
注册树模式:
namespace IMooc;
class Register
{
protected static $objects;
static function set($alias,$object){
self::$objects[$alias]=$object;
}
static function get($alias){
return self::$objects[$alias];
}
static function _unset($name){
unset(self::$objects[$name]); }}
namespace IMooc;
class Register
{
protected static $objects;
static function set($alias,$object){
self::$objects[$alias]=$object;
}
static function get($alias){
return self::$objects[$alias];
}
static function _unset($name){
unset(self::$objects[$name]); }}
2016-03-03
工厂模式:
namespace IMooc;
class Factory
{
protected static $db;
static function createDatabase(){
self::$db= Database2::getInstance();
\IMooc\Register::set("db1",self::$db);
return self::$db;
}
}
namespace IMooc;
class Factory
{
protected static $db;
static function createDatabase(){
self::$db= Database2::getInstance();
\IMooc\Register::set("db1",self::$db);
return self::$db;
}
}
2016-03-03
单例模式:
namespace IMooc;
class Database2
{ protected static $db;
private function __construct()
{
}
static function getInstance(){
if(self::$db instanceof self){
return self::$db;
}else{
self::$db= new self();
return self::$db;
}}}
namespace IMooc;
class Database2
{ protected static $db;
private function __construct()
{
}
static function getInstance(){
if(self::$db instanceof self){
return self::$db;
}else{
self::$db= new self();
return self::$db;
}}}
2016-03-03
这个代理模式不错,潘金莲的故事
http://www.cnblogs.com/zemliu/archive/2012/05/20/2509377.html
http://www.cnblogs.com/zemliu/archive/2012/05/20/2509377.html
2016-02-26
//男、女、不男不女
if(isset($_GET['sex'])){
$sex = $_GET['sex'];
}else{
$sex = 'Female';
}
$page = new Page();
$classstr = '\\com\\strategy\\'.$sex.'Strategy';
$page->setStrategy(new $classstr());
$page->index();
if(isset($_GET['sex'])){
$sex = $_GET['sex'];
}else{
$sex = 'Female';
}
$page = new Page();
$classstr = '\\com\\strategy\\'.$sex.'Strategy';
$page->setStrategy(new $classstr());
$page->index();
2016-02-20