Placement of a call to the parent method
- by Alejandro
I have a class that has a method. That class has a child class that overrides that method. The child's method has to call the parent's method. In all OO that I've seen or written calls to the parent's version of the same method were on the first line of the method. On a project that I am working on circumstances call for placing that method call at the end of a method. Should I be worried? Is that a code smell? Is this code inherently bad?
class Parent {
function work() {
// stuff
}
}
class Child {
function work() {
// do thing 1
// do thing 2
parent::work(); // is this a bad practice?
// should I call the parent's work() method before
// I do anything in this method?
}
}