0
有一个单独的对象,它负责生成网页的内容,我们可以把它叫做内容。另一个对象是它的'父母 - 核心对象。 内容对象调用核心方法* Check_parameters_count($ parameters_count)*,所以核心有检查,如果给定参数的URI数等于在执行这个方法($ parameters_count)给出的整数,如果不是 - 核心应该生成错误页面并停止执行内容的渲染方法。
有没有什么办法可以做到这一点,而不使用如果声明?只需在内容类中使用* $ core-> Check_parameters_count(2)*以简化特定渲染引擎程序员的工作。
一切看起来应该与此类似:
class Core {
public function Check_parameters_count($parameters_count) {
if (count($this->parameters) != $parameters_count) {
$this->Show_error(404);
$this->Stop_executing($content, 'Render');
//or
stop($content->Render);
//or something similar..
}
}
}
class Content {
public function Render() {
//check given parameters so we could know which page should be rendered and how many parameters should be given
//...
//lets say we should have exactly 2 parameters
$parameters_count = 2;
//check it
$core->Check_parameters_count($parameters_count);
//if parameters count matched - continue method execution
//...
}
}
好主意:)这正是我一直在寻找的。 这是第一次例外对我有用,因为我总是停止使用它们,因为同时缺少多错误投掷。 –