Placement of a call to the parent method

Posted by Alejandro on Stack Overflow See other posts from Stack Overflow or by Alejandro
Published on 2010-04-14T04:25:00Z Indexed on 2010/04/14 4:33 UTC
Read the original article Hit count: 260

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about oop

Related posts about inheritance