The Science of Programming/SwayPresentations/Objects/VariationInheritance

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

Variation Inheritance

Variation inheritance: whereby the subclass changes a behavior of the super class.

   function super()
       {
       var greeting = "hello";
       function a() { greeting; }
       this;
       }
   
   function sub()
       {
       function a() { "well, " + a . prior() + " there!"; }
       extends(super());
       }
   
   var s = sub();
   
   println(s . a());

The output is:

   well, hello there!

Looking at the s object gives:

   <OBJECT 2611>:
       context: <OBJECT 654>
       dynamicContext: <OBJECT 654>
       callDepth: 1
       constructor: <function sub()>
       this: <OBJECT 2611>
       a: <function a()>
       a: <function a()>
       greeting: "hello"

Next Previous Top