Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

The Science of Programming/SwayPresentations/Objects/ClassesViaConcatenation

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

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"; } Next Previous Top