< The Science of Programming < SwayPresentations < Objects 
    
      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"; } | 
    This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.