The Science of Programming/SwayPresentations/Objects/ClassesViaConcatenation
Inheritance via Concatenation
The idea is from Antero Taivalsaari.
Concatenate the environment of the subclass and the superclass.
Now, looking up a component of a superclass is exactly the same process as looking up a component of the subclass.
class g { var x = 2; function me("I'm g"); } class f extends g { var y = 4; function me("I'm f"); }
Make some objects:
var gobj = new g; var fobj = new f;
gobj's environment:
variable | value |
---|---|
x | 2 |
me | lambda() { "I'm g"; } |
fobj's environment:
variable | value |
---|---|
y | 4 |
me | lambda() { "I'm f"; } |
x | 3 |
me | lambda() { "I'm g"; } |