I am trying to build a simple abstract Cache class that can enforce methods in subclasses and I am trying to set up default settings for the subclasses to inherit. Here is my basic run down:
define('APP_ROOT', getcwd());
abstract class BaseCache {
protected $baseCacheDir = APP_ROOT . '/cache';
abstract function exists($resource);
abstract function store($resource);
abstract function delete($resource);
abstract function check($resource);
}
class TemplateCache extends BaseCache {
protected $CacheDir = $this->baseCacheDir . '/tpl/';
public function exists($resource) {}...
}
class LinkCache extends BaseCache {
protected $CacheDir = $this->baseCacheDir . '/link/';
}
Is this the proper/best practices way to do this? Is this how you access properties in abstract classes while in a subclass? The $baseCacheDir property shouldn’t be changed and I want to hard-code it in as a default, then have subclasses build off of the base directory. (e.g ‘cache/link’, ‘cache/tpl’, ‘cache/apc’, ‘cache/memcache’)
Thanks.
1 Answer