CHAPTER 12 ■ ENTERPRISE PATTERNS
241
You may wonder why this code takes it on trust that the Command class it locates does not require
parameters:
if ( $cmd_class->isSubClassOf( self::$base_cmd ) ) {
return $cmd_class->newInstance();
}
The answer to this lies in the signature of the Command class itself.
Namespace woo\command;
//...
abstract class Command {
final function __construct() { }
function execute( \woo\controller\Request $request ) {
$this->doExecute( $request );
}
abstract function doExecute( \woo\controller\Request $request );
}
By declaring the constructor method final, I make it impossible for a child class to override it. No
Command class, therefore, will ever require arguments to its constructor.
Remember that you ...