I would like to ask several questions regarding programming in OOP PHP. Last time, I have written several classes (i.e. for cache and logging support), but I have not used namespaces. Now I would like to introduce them and I wonder if it makes any sense of creating as many namespaces as are available in other projects available on the net for free. Actually I am thinking about creating \Framework namespace, where all my classes could fit w/o worrying about name conflicts. However, someone might suggest to use some sub-namespaces, like \Framework\Cache or even \Framework\Cache\Driver\Apc. This leads to many namespaces, containing only few (or even just one) class inside. Do you see any reason for creating as many namespaces? What would you recommend?
Final question is more about design. As I have written, I have several classes that provides support for caching. One, main Cache class and some helpers. I have also written drivers for file-based cache, apc, etc. Actually there is Cache::loadDriver method, that takes care about loading proper driver. It is sufficient, to pass 'apc' string as parameter, and it will automatically load the proper driver, by simply creating an object:
Code: Select all
$driver = 'apc'; $classname = '\Framework\Cache\' . strtoupper($driver); $this->driver = new $classname();
I am looking forward to hear your opinions.