Überschreiben der Methoden einer Elternklasse

Etwas, das ich sehe Menschen, tun, die ganze Zeit ist:

class Man(object):
    def say_hi(self):
        print('Hello, World.')

class ExcitingMan(Man):
    def say_hi(self):
        print('Wow!')
        super(ExcitingMan, self).say_hi()  # Calling the parent version once done with custom stuff.

Etwas, das ich nie sehen, Menschen tun ist:

class Man(object):
    def say_hi(self):
        print('Hello, World.')

class ExcitingMan(Man):
    def say_hi(self):
        print('Wow!')
        return super(ExcitingMan, self).say_hi()  # Returning the value of the call, so as to fulfill the parent class's contract.

Ist dies, weil ich Hänge mit den falschen Programmierer, oder ist es für einen guten Grund?

InformationsquelleAutor der Frage orokusaki | 2010-09-27

Schreibe einen Kommentar