Modes of method inheritance - delegate - provide


Let the child implement the functionality.


examples/oop/inheritance/delegate.py
class Parent():
    def greet(self):
        print("Hello", self.get_name())

class Child(Parent):
    def __init__(self, name):
        self.name = name

    def get_name(self):
        return self.name

# Should not create instance from Parent
p = Parent()
# p.greet()    # AttributeError: 'Parent' object has no attribute 'get_name'

c  = Child('Foo')
c.greet()    # Hello Foo