In this question about including all the classes in a directory for an interpreter that needs all of them, it was suggested that a better way to handle the problem would be to conditionally include only the Command file that is needed for this iteration of the interpreter. For example, instead of this:
require_once('CommandA.php');
require_once('CommandB.php');
require_once('CommandC.php');
class Interpreter {
public function interpret($action) {
switch($action) {
case 'A':
$c = new A();
$c->execute();
break;
}
}
}
Do something more like this:
class Interpreter {
public function interpret($action) {
switch($action) {
case 'A':
require_once('CommandA.php');
$c = new A();
$c->execute();
break;
}
}
}
What are the advantages and disadvantages of going with the second choice -- dynamically and conditionally loading only the needed command -- as opposed to the first one -- including all of the files at the head of the file, C-style?
In the answer given to my previous question, speed, footprint and ease of writing were listed as advantages of conditionally loading. In other questions where this is addressed, I've seen it suggested that c-style loading is more readable and maintainable. Can anyone elaborate on these? Any other advantages or disadvantages?