Objects consist of variables and functions which are written in one file per object blueprint.
But it would be wearisome if we had to write every function anew just because we'd like
to have a torch beside a lamp. That's where inheritance comes into play. The
statement allows to include all the variable declarations and functions of a blueprint
into another object. After that you can modify the behaviour by overloading functions.
The inherit statement must come before any variable or function declaration. If there is no blueprint for the given file name then this file will be compiled first. Also there may be more than one inherit statement to combine functionality from several blueprints
When inheriting the variables and functions of a blueprint their modifiers are applied.
That means as
private declared variables or functions are not accessible for the inheriting object.
protected functions however are. It's also possible to add modifiers to all inherited variables and functions:
But it's not possible to make private variables or functions public or vice-versa.
After having inherited a lot of functions it's possible to overwrite some of them simply by defining functions with them same name in the object's file. Whenever the function with this name is called (even by other inherited functions) then your new function will be called instead. This is called overloading.
Nevertheless you can explicitly call the original inherited function by prepending
the function name with
take_it in the first inherited blueprint that defines this function.
You can specify the inherited blueprints name to avoid ambiguitiy:
To call a function in all inherited programs use