Problem Set 5: In the solutions, why do the functions for SubjectTrigger and SummaryTrigger have __init__ functions defined? Don't they just inherit the ones that they define from their superclass anyway?
To write it out, a superclass WordTrigger is created like so: class WordTrigger(Trigger): def __init__(self, word): self.word = word but then SubjectTrigger and SummaryTrigger have this defined: # TODO: SubjectTrigger class SubjectTrigger(WordTrigger): def __init__(self, word): WordTrigger.__init__(self, word) Isn't that unnecessary? Why is it there?
WordTrigger inherits from Trigger, the __init__() function assigns the variable word into the instance of WordTrigger (the local namespace) being declared.
But shouldn't that __init__() function be inherited anyway? I understand the purpose of __init__, but not why the valid one from the superclass is being overwritten by an identical one in the subclass.
In that case, the __init__() function of the superclass is being overridden by the subclass, just like any other method.
Join our real-time social learning platform and learn together with your friends!