2 ms·
You don't lose inheritance. This is especially clear in Python, e.g. class Foo(Baz): def foo(self, bar): return self.baz(bar + 1) Notice tha
by chriswarbo 6y ago
You don't lose inheritance. This is especially clear in Python, e.g.
class Foo(Baz):
def foo(self, bar):
return self.baz(bar + 1)
Notice that we're not calling the 'baz' method via some fixed lexical variable; we're looking it up in the 'self' object, which has been passed in (implicitly) as an argument ('self' will also implicitly be passed into 'self.bar' as its first argument). Java's 'this' serves a similar role, except even more things are done implicitly.
One slight complication: 'self' should be lazy, so we can take the fixed point (so every method sees all of the overrides). This is easy in lazy languages (e.g. Nix); in strict languages we can just make 'self' a function: it looks up a given name in the object's properties/methods, and if not found it invokes the superclass (AKA 'super').