I get that the first methodology here is supposed to be bad, and the second one is suggested as better. But I’m not sure I really know why. The first way, the parent method is called, which then calls the child method to get more specifics. That seems less verbose than the second way, and I’m not sure I see anything wrong with it. But – you all tell me. And how wrong is wrong? Will I be ridiculed forever doing it that way?
(I first posted this in the discussion forum since it seemed like a philosophical question, but it got deleted and I was told to ask it as a question – so here I am)
class Parent_Class {
function generate_results() {
// ... do some things first that any child would need
// ... then do more specific child things
$this->generate_more_results();
}
}
class Child_Class_A extends Parent_Class {
function generate_more_results() {
// ... do more things
}
}
class Child_Class_B extends Parent_Class {
function generate_more_results() {
// ... do more things
}
}
$a = new Child_Class_A();
$b = new Child_Class_B();
$a->generate_results();
$b->generate_results();
------
class Parent_Class {
function generate_results_init() {
// ... do initial things germane to all children
}
}
class Child_Class_A extends Parent_Class {
function generate_results() {
$this->generate_results_init();
// ... do more things
}
}
class Child_Class_B extends Parent_Class {
function generate_results() {
$this->generate_results_init();
// ... do more things
}
}
$a = new Child_Class_A();
$b = new Child_Class_B();
$a->generate_results();
$b->generate_results();