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>\n";
}
function fly
{
display "{arg%who} fly {arg%this}<br>\n";
}
function dontknow
{
display "{arg%who} don't know what to do with {arg%this}<br>\n";
}
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";
|