Topic: APLX Help : Help on APL language : System Methods : ⎕BASE Base (parent) class
[ Next | Contents | Index | APL Home ]

www.microapl.co.uk

⎕BASE Base (parent) class


Implemented for Internal and External classes. Not implemented for System classes.

Syntax:

    classref ← objref.⎕BASE
    classref ← classref.⎕BASE
    classref ← ⎕BASE      (Within user-defined method, same as ⎕THIS.⎕BASE)

The niladic system method ⎕BASE returns a reference to the base (parent class) of either an object, or a class. The result is always a class reference, or the Null object if there is no parent. For example, if class Car inherits from class Vehicle:

      )CLASSES
Car     Vehicle
      M←⎕NEW 'Car'
      M
[Car]
      M.⎕CLASSREF
{Car}
      M.⎕BASE
{Vehicle}
      
      M.⎕NL 2        ⍝ Child has properties of its own, plus those of parent
Marque
Owner
HasEngine
IsPublicTransport
Passengers
TopSpeed
Wheels 

      M.⎕BASE.⎕NL 2  ⍝ Parent has fewer properties than the child
HasEngine
IsPublicTransport
Passengers
TopSpeed
Wheels       

A common use for ⎕BASE is calling the parent's version of a method within the child's version of the same method. Typically, the need for this arises when the child class needs to do some extra processing in addition to what the parent does. You have full control over this; the child method (which in APLX always overrides the parent's method) can call the parent's version either at the beginning, in the middle, or at the end of its own version of the method - or indeed, not call it at all.

⎕BASE can also be used with External classes (but not System classes). For example, in the .Net System.Windows.Forms framework, the Button class inherits from the ButtonBase class, which in turn inherits from the Control class:

      BT←'.net' ⎕NEW 'System.Windows.Forms.Button'
      BT.⎕BASE
{.net:ButtonBase}
      BT.⎕BASE.⎕CLASSNAME
.net:System.Windows.Forms.ButtonBase
      BT.⎕BASE.⎕BASE.⎕CLASSNAME
.net:System.Windows.Forms.Control

Similarly, in Ruby, the DateTime Class inherits from the Date class, which in turn inherits from the fundamental Object class (from which all classes in Ruby are derived). This example shows how this looks from within APL:

      'ruby' ⎕SETUP 'require' 'date'
      DT←'ruby' ⎕NEW 'DateTime'
      DT                             ⍝ Reference to a DateTime object
[ruby:DateTime]
      DT.⎕BASE                       ⍝ Reference to parent class (Date)
{ruby:Date}
      DT.⎕BASE.⎕CLASSNAME
ruby:Date
      DT.⎕BASE.⎕BASE.⎕CLASSNAME
ruby:Object
      DT.⎕BASE.⎕BASE.⎕BASE
[NULL OBJECT]

Topic: APLX Help : Help on APL language : System Methods : ⎕BASE Base (parent) class
[ Next | Contents | Index | APL Home ]