Код: Выделить всё
class Service {
protected static $instance;
public function Service() {
if (isset(self::$instance)) {
throw new Exception('Please use Service::getInstance.');
}
}
public static function &getInstance() {
if (empty(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
}
Код: Выделить всё
class FileService extends Service {
// Lots of neat stuff in here
}
Есть ли другой способ добиться того, чего я хочу? Одноэлементный код состоит всего из нескольких строк, но мне бы хотелось по возможности избегать избыточности кода.
Подробнее здесь: https://stackoverflow.com/questions/312 ... ons-in-php