<?php
/**
- 单例模式
- 工厂模式
- 注册模式
/
// 单例模式
class Site
{
publicinstance = null;
//禁用构造器
private function __construct(this->siteName =
siteName = 'PHP中文网')
{
if (!self::instance = new self(
instance;
}
}
// 工厂模式
class Factory
{
public static function create()
{
return Site::getInstance('www.php.cn');
}
}
//注册树
/* - 1.注册:将对象挂到树上
- 2.获取:将对象从树上取下来
- 3.删除:把对象吃掉
*/
class Register
{
protected statickey,
objects[
obj;
}
public static function get(objects[
key)
{
unset(self::key]);
}
}
Register::set('site', Factory::create());
obj->siteName);
网友评论