overriding a critical base method while preserving its functionality without making my code smelly

Calling the parent is a kind of habit ; it’s actually (most of the time) pretty nice to have the choice.

If you really don’t want to call the parent method, an alternative would be to add your own overridable method in Merchant:

extends Merchant
class_name Salesman

func greet():
    print("Hello!")

func meet_customer():
    pass  # override me

func on_met_customer():
    greet()
    meet_customer()
    rob_customer()
    # …

and then override that in the child:

extends Salesman
class_name CarSalesman

func shake_hands():
    print("*handshake*")
    
func meet_customer():
    shake_hands()

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top