Inheritance
Username:  
Password:
  > Home
> User Guide
v Reference
    > Introduction
    > CROFT
    > BEE Variables
    > BEE Syntax
    > BEE Commands
    > Database Operation
    > Content Management
    v Objects and Classes
       o Classes
       v Objects
          o The Constructor
          o Calling an Object Method
          o Polymorphism
          o Inheritance
          o Object within Object
    > Interface with others
    o Glossary
> Portal Object
> Development Guide


Shortcuts
sys Class
debug Class
Intrinsic Conversions
>> Reference >> Objects and Classes >> Objects >> Inheritance <=  =>      <  1  >  
Inheritance

Inheritance in BEE is done by the child's constructor calling the parent's, so the object have all the child's variables (object attributes) and functions (method), PLUS all the parent's variables and functions.

In the following example, Vehicle has two Child classes: car and plane.  We use the same constructor vehicle in the previous example and create two more:

function vehicle

{

   var this%make = "{arg%m}";

   var this%capacity = "{arg%c}";

   var this%function:do = "dontknow";

}

 

function car

{

   this%vehicle m="{arg%m}" c="{arg%c}";

   var this%wheel = "{arg%w}";

   var this%function:do = "drive";

}

 

function plane

{

   this%vehicle m="{arg%m}" c="{arg%c}";

   var this%engine = "{arg%e}";

   var this%function:do = "fly";

}

 

function drive

{

   display "{arg%who} drive {arg%this}<br> ";

}

 

function fly

{

   display "{arg%who} fly {arg%this}<br> ";

}

 

function dontknow

{

   display "{arg%who} don't know what to do with {arg%this}<br> ";

}

 

var myCar% = new car m="Toyota" c="4" w="alloy";

var myPlane% = new plane m="Boing" c="400" e="jet";

var mySpaceship% = new vehicle m="Alien Nation" c="4000";

 

myCar%do who="I";

myPlane%do who="You";

mySpaceship%do who="We";

 

 

Note: When an object function needs to call another function of the same object, it is recommended to call into the absolute name instead of the object function name in case the callee function is overloaded.  For example:

function vehicle

{

   var this%make = "{arg%m}";

   var this%capacity = "{arg%c}";

   var this%function:do = "dontknow";

   var this%function:start = "vehicle_start";

   var this%function:findkey = "vehicle_findkey";

}

 

function car

{

   this%vehicle m="{arg%m}" c="{arg%c}";

   var this%wheel = "{arg%w}";

   var this%function:do = "drive";

}

 

function vehicle_start

{

   this%findkey;  // For safety, replace this by this%vehicle_findkey;

   display "Start Vehicle.<br> ";

}

 

function vehicle_findkey

{

   display "Find the key of the Vehicle.<br> ";

}

 

The above worked fine, but if the constructor of "car" overload the function findkey (e.g. var this%function:findkey = "car_findkey";), then vehicle_start will call into "car_findkey".  If this is not your intention, please replace "this%findkey;" with "this%vehicle_findkey;".

Calling on the actual function name allows the children object to call an overloaded parent function without ambiguity.

 

 

Previous Page       Next Page

Accsoft Computer Technology Pty Ltd     ABN: 98 065 617 549
PO Box 892, Epping NSW 1710         Level 1, Epping Office Park, 242 Beecroft Rd, Epping NSW 2121, Australia
Tel: Sydney - (02)98691668     National - 1300-881668         Fax: (02)98691866
© Copyright 2003 Accsoft Computer Technology Pty Ltd