The Science of Programming/SwayPresentations/Objects/ReificationInheritance

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Reification Inheritance

Reification inheritance: whereby the subclass completes (or partially completes) an incomplete superclass.

   function super()
       function a(x) { b(x * x); }
   function sub()
       function b(y) { y + 1 * (y - 1); }

Now we make a sub object:

   var s = sub();
   inspect(s . a(3));

The output is:

   s . a(3) is 80

Sway allows you to look at the concatenated environment:



   <OBJECT 5651>:
       context: <OBJECT 654>
       dynamicContext: <OBJECT 654>
       callDepth: 1
       constructor: <function sub()>
       this: <OBJECT 5651>
       b: <function b(y)>
       a: <function a(x)>

Next Previous Top