-
Notifications
You must be signed in to change notification settings - Fork 3
2.1 Constructor & Deconstructor
Constructor & Deconstructor functions in OOP have a special usage. When you call them, you do it through the class not through the instanciation of an object. It's a bit complicated to understand at the begining but you should just retain that to call them you use the class.
Constructor is the first function that is call at the instanciation of your object. Its role is to initialise the variable of the object. Opposite to other language, the name of constructor in OOP is constructor.
To instanciate an object in OOP we call the function new wich is an alias of the declared function constructor
Constructor function must be declare and have visibility PUBLIC
Example
PUBLIC FUNCTION("string","constructor") {
MEMBER("name",_this);
};
_myfooobject = ["new", "Thomas"] call OO_FOO;
ou
_myfooobject = NEW(OO_FOO,"Thomas");
will instanciate a _myfooobject, and set its name variable to Thomas and for this you use the class OO_FOO
Constructor is the last function wich is called at the destruction of the object. Its role is to clean all the object's variables.
To call the deconstructor we call the function delete wich is an alias of the declared function deconstructor
Deonstructor function must be declare and have visibility PUBLIC
Example
PUBLIC FUNCTION("string","deconstructor") {
DELETE_VARIABLE("name");
};
["delete", _myfooobject] call OO_FOO;
ou
DELETE(_myfooobject);
will destroy the _myfooobject and erase the content of name variable with nil and for this you use the class OO_FOO