Overriding printString |
Category: |
RPL
Applicable to: |
All Versions
Description: |
In RPL you can override the printString method with:
printString
| |
"do whatever you want"
Here are some other useful techniques extracted from the 5.0 RPL guide.
An RPL code segment in an actor or data class can invoke a function or method, within an instance of a class, using the invocation statement `SELF , where the selector is the method name with arguments. For example the method:
myPrintString
| |
^ `+++ `, SELF printString
would prefix the string "+++ " to a class's default printString method.
At run-time, the method that is called is the first method of that name found (e.g., printString) going up the class inheritance hierarchy, starting with the class of the actor or data object. If no method of that name is found, a run-time error occurs.
A locally defined method can be defined with the same name as an inherited method (in which case the locally defined method overrides the inherited method). A locally defined method which overrides an inherited method of the same name can call the method on its superclass by the invocation statement `SUPER . For example:
printString
| |
^ `+++ `, SUPER printString
overrides a classes default printString method.
Alternatively, the simpler statement CALLSUPER can be used to call the superclass method passing the same arguments as received by the caller. For example the previous example could be written:
printString
| |
^ `+++ `, CALLSUPER
In each case, a run-time error will occur if no such method is defined in an ancestor of the class where the calling method is defined.
You can only add new functions, and hence override them, with subclasses of Sequence, SequenceOf, Enumerated, and Choice (RPL only)
Copyright © 1999, ObjecTime Limited. |