Object oriented
Inheritance
v2.0 lets a class borrow a parent, rewrite a method, and still say parent when it misses home.
Runtime polymorphism showed up too. I did not make it a sandwich. I made it a family tree.
The basics still live next door: fields, constructor, methods, self, newobj.
extends
extends names the parent. The child inherits the public fields and methods. The constructor still has to introduce itself.
define class Dog extends Animal;
public:
define constructor(str name);
call parent(name);
end;
end;
parent
parent is self, aimed upstairs.
call parent(name); runs the parent constructor.
call parent.Description(); reaches the original method, even after you overrode it.
define constructor(str name);
call parent(name);
end;
define override func Description() returning str;
return call parent.Description() + " is a developer";
end;
override
override replaces a parent method. Same name, same manners, new personality.
define override func Speak() returning str;
return "Woof!";
end;
abstract
abstract is a class that refuses to be built until a child finishes the homework.
You cannot newobj it. You can type a variable as it, then fill the chair with a child.
That is runtime polymorphism, wearing a dress.
define abstract class Shape;
public:
define abstract func Area() returning decimal;
end;
define class Square extends Shape;
private:
define decimal size is new;
public:
define constructor(decimal size);
redefine self.size is size;
end;
define override func Area() returning decimal;
return self.size times self.size;
end;
end;
define Shape shape is newobj Square(4.0);
showln call shape.Area();
isa
isa asks whether an object is compatible with a class —
itself, or a parent. This is not is. is still assigns. Always.
define Dog dog is newobj Dog("Rex");
if dog isa Animal;
showln true;
end;
Walkthroughs: basic inheritance, parent, override, abstract.