1
我需要为我的简单项目提供建议。这是一个记录系统。我有以下文件/类需要针对设计模式的建议
文件 - 检查文件是否存在,是否可读等
ConfigParser - 这是一个抽象类,我用__construct的方法做一些事情。该类从不直接实例化。这是一个装饰者。
abstract class ConfigParser
{
protected $filename;
public function __construct($file)
{
// Here I want to invoke validate() method of File class
// I know that I can do $file = new File(); $file->validate()
// but the idea is to keep the things decoupled
// Also I know that I can extend the File class ConfigParser extends File
// but this doesn't make sence
// I can pass the File object on child class new XmlParser('file.xml', $fileObj)
// but this doesn't make sence too.
// I don't want to use traits as it's bizarre for me
}
}
XmlParser的 - 扩展ConfigParser
IniParser - 扩展ConfigParser
由于该项目的目标是保持脱钩我无法弄清楚如何实施此方案中的File类的类。
我不知道这可能更适合在http://codereview.stackexchange.com/ – kkuilla
您可能会发现这个答案相关:http://stackoverflow.com/a/18682856/727208 –