MySQL
- 7 ответов
- 0 вопросов
2
Вклад в тег
abstract class DataKeeper {
protected $data;
public function setData($data) {
$this->data = $data;
}
public function getData() {
return $this->data;
}
abstract public function save()
abstract public function process()
}
class FileDataKeeper extend DataKeeper {
public function save() {
// implementation
}
public function process() {
// implementation
}
}
class Container {
protected static $classes = array();
public static function register($alias, $class) {
self::$classes[$alias] = $class;
}
public static function get($alias) {
if (!isset(self::$classes[$alias]))
throw new Exception("...");
$className = self::$classes[$alias];
return new $className();
}
}
// bootstrap.php
Container:register("dataKeeper", "FileDataKeeper");
// SomeWhere.php
$dataKeeper = Container::get("dataKeeper");