Documentation of MathOO
It is a documentation of MathOO, listing most of its functions and usage.
Content |
NewClass
usage:
NewClass[class (,parent1, parent2...)] make a new class which inheritance from parent1, parent2... if parent1, parents ... are provided.
example:
NewClass[UnitTest, Test, Object]
creats UnitTest as a class, which inheritance from Test and Object. The method of inheritance is using C3 method resolution order.
new
usage:
new[class][x, y, ..] creates a new object from the class with x, y, ... as the argument to the constructor of class.
example:
unitTest = new[UnitTest][filename];
creates a new object from the class UnitTest, with filename as the argument to the constructor UnitTest.$init$ and finally assign the new object to x.
Super
usage:
Super[class] returns the parent of class
example:
Super[UnitTest].$init$[unitTest, x]
calls the parent of UnitTest, which is Test in this case. So, it tries to run:
Test.$init$[unitTest, x]
If Test.$init$ is not provided, MathOO will try to call Object.$init$ instead.
delete
usage:
delete is used to delete a class, an object, or a attributes or method.
example:
delete[x]
deletes the object, or class x. And
delete[x.y]
deletes the attribute or method y from x.
hasAttr
usage:
hasAttr[class,attr] checks whether a class/object has element attr. Notice attr has to be string.
Example:
x = new[Object][];
x.a = 5;
hasAttr[x, "a"]
Output: True
ClassQ
usage:
ClassQ[c] checks whether c is a class or not.
ObjectQ
usage:
ObjectQ[c] checks whether c is an object or not.
ClassObjectQ
usage:
ClassObjectQ[c] checks whether c is an object or a class or not.
static
usage:
static[UnitTest.test] defines test to be a static method of the class UnitTest.
example:
static[UnitTest.error];
UnitTest.error[s_]:=Print["Error :",s];
unitTest.error["overflow"];
This example define the function UnitTest.error as static function. So it does not need the self_ argument. You can call this function from any instance of UnitTest.
Object
usage:
Object is an empty class which only have $init$ defined.
example:
a = new[Object][];
a.x = 1;
a.y = 2;
It creates a object a, which has no attributes defined at all. You can use as a structure to store different variables so that it won't pollute the global namespace.
Please login to post comment.