This, Super, Descendants and Objects
There are two special symbols that can be used to reference a class member relative to a current position. First,
This is used to resolve ambiguities, if a method contains a parameter and a class member with the same name. The next class contains a method that squares its parameter and adds the equally named class member.
The call to
f shows the intended behavior. Because we do not need the generated object, but for the call, we chain the
Dot operator.
| Out[3]= |  |
Members in parent classes can be accessed by means of
Super. The next class inherits from the previously defined
base class and accesses its method
f. Because functionality of a parent class is replaced, we qualify the member with
Override.
Calling this new method shows the desired result
x^3+4*x^2+100.
| Out[5]= |  |
Every class registers with its parent. All children of a class may be listed with
Descendants.
| Out[6]= |  |
Adding another child class grows the list.
| Out[8]= |  |
Super[class] lists the complete chain of inheritance.
| Out[9]= |  |
| Out[10]= |  |
All objects generated by a class may be listed with
Objects[class]. The package itself uses the list only in
RemoveObjects and it can be modified as long as it stays a list.
| Out[11]= |  |
| Out[12]= |  |
Any new object is added to the list. Referenced objects can be listed by
Objects[object]. This list is built on demand.
| Out[13]= |  |
| Out[14]= |  |
There is a test function
ObjectQ to check, if something is an object.
| Out[15]= |  |