我正在使用MVC架构开发一个php应用程序,我确实需要关于以下设计准则的建议:
根据php类结构最佳实践,它指出某人应该最小化模块依赖,我的应用程序类继承如下:
班级组织:
interface StringHelper{
...
}
interface ArrayHelper{
...
}
class GeneralHelper implements StringHelper, ArrayHelper{
......
}
class NewClass extends GeneralHelper{
...
}
// user factory style to create object
class NewClassFactory{
public function create( $options ){
return new NewClass( $options );
}
}应用程序大约有15个类。
这种方法是否适合于这种情况,还是在维护我的应用程序时我会遇到很大的问题?会感谢你的帮助。
发布于 2012-06-30 20:30:17
在大多数情况下,助手类应该始终是静态的,任何工作类都不应该扩展它。帮工是全球性的,他们在工人阶级的主要范围内没有任何作用。把帮手想象成管道工、杂工等。如果你在写一个家庭类,它不应该扩展水管工,管道工应该在需要的时候进来,不应该和家庭有任何关系。
你需要的是:
class NewClass {
...
$some_string = declaration
$some_string = StringHelper::sanitizeString($some_string);
}https://stackoverflow.com/questions/11277339
复制相似问题