可能碰巧有一个类实现了如下接口:
interface ICommand
{
public function execute();
}
class deleteCommand implements ICommand
{
public function execute() {
if($this->validateConditions()) {
$this->performExecute()
} else {
// do something else ..
}
}
public function performExecute() {
// the real code we want to execute
}
}
我的问题是:
有第二个方法来真正执行应该留在接口方法中的操作,这种模式有名字吗
我可能听说过一些术语,比如performExecute()方法是"模板",但我不确定。我想这应该是某种抽象模式。
有人能给这种模式起一个合适的名字吗?或者给我指一些文章/文档
如果在"helper"对象上调用performExecute
,那么它将是Delegate Pattern。如果没有这层抽象,我认为它不是一个官方的设计模式,而只是正常的子程序使用。