Search code examples
phpdesign-patternsinterfaceabstraction

Design pattern name for implementation of interface method delegating the core functionality to another method


Can happen to have a class that implements an interface like:

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
    }
}

My question is:

Does this pattern, of having a second method that really perform the operations supposed to stay in the interface method, has a name?

I maybe heard some term like performExecute() method is a "template", but I'm not sure. I guess this should be some kind of abstraction pattern.

Can someone give a proper name to this pattern? Or maybe point me to some article/documentation?


Solution

  • If you were calling performExecute on a "helper" object then it would be the Delegate Pattern. Without that layer of abstraction, I think it's less of an official Design Pattern and more just normal subroutine usage.