Re:Closures and Objects Are Equivalent (2013)
by jasonwatkinspdx on Sunday November 20, 2022 @06:39AM
(#33680154)
Delegation can model inheritance or other OOP semantics. If you squint your eyes delegation and lexical scope nesting kinda resemble each other.
[ Parent
| on HN ]
Re:Closures and Objects Are Equivalent (2013)
by _old_dude_ on Sunday November 20, 2022 @09:01AM
(#33680936)
This is especially true in JavaScript. Inheritance between classes is implemented using delegation and the global scope is dynamic.
Re:Closures and Objects Are Equivalent (2013)
by zozbot234 on Sunday November 20, 2022 @09:25AM
(#33681111)
Not quite. Inheritance needs a "tying the knot" construction, because a base-class method can call a method that may have been overridden in a derived class. So you need an indirection step for any call to an overridable method, which cannot be modeled by simple delegation. Of course this is really a misfeature (outside of pure abstract base classes that, like interfaces or traits, don't implement their defined methods), which is at the root of the well-known "fragile base class" problem. It means implementation-inheritance is inherently non-modular, even though literally everything else in OOP was specifically intended to enable and promote modularity.