Augmenting Inherited Methods
Each method that is inherited from a superclass can be augmented to perform some different action in the new class. If there is no augmentation, the inherited methods will perform as defined in the superclass.
An inherited method is augmented simply by creating a new definition for the method in your class definition. The following example demonstrates augmenting an inherited method:
Class cMessageButton1 is a Button
Procedure DoShowSomething
Send Info_Box "First Message"
End_Procedure
Procedure OnClick
Send DoShowSomething
End_Procedure
End_Class
Class cMessageButton2 is a cMessageButton1
Procedure DoShowSomething
Send Info_Box "Second Message"
End_Procedure
End_Class
In this example, the first class cMessageButton1 defines a new method DoShowSomething that displays the message "First Message". Thus, an object of this class, when clicked, would show the message "First Message". The second class cMessageButton2 inherits DoShowSomething and OnClick from cMessageButton1, but it augments DoShowSomething to display a different message. An object of this class, when clicked, would show the message "Second Message."
Message Forwarding
A more sophisticated way to augment an inherited method involves forwarding. Message forwarding allows you to augment an inherited method in such a way that it can perform its inherited action and some new action.
All three method types can be forwarded (Procedure, Procedure Set, and Function). Messages are forwarded by executing a Forward statement. The syntax for forwarding a message is different for each type of method as outlined below:
Forwarding Procedure Methods
Forward Send {method-name} {Param1 … ParamN}
Forwarding Procedure Set Methods
Forward Set {method-name} {Param1 … ParamN} To {value1 … valueN}
Forwarding Function Methods
Forward Get {method-name} {Param1 … ParamN} To {receiving-variable}
You can see that the syntax for forwarding a message is the same as the syntax for executing a method, except that the Forward command is appended to the front of each statement. There is also no object reference when forwarding a method. You are always forwarding the message to the superclass of the current object.
An example of method augmentation with message forwarding follows:
Class cMessageButton is a Button
Procedure Construct_Object
Forward Send Construct_Object
Property String psMessage Public "First Message"
End_Procedure
Procedure OnClick
String sMessage
Get psMessage To sMessage
Send Info_Box sMessage
End_Procedure
End_Class
Class cShowLabelButton is a cMessageButton
Procedure Set Label String sLabel
Forward Set Label To sLabel
Set psMessage To sLabel
End_Procedure
End_Class
In this example, the first class augments the Construct_Object method of cMessageButton to define a new string property. Note that Construct_Object is forwarded to ensure that all the superclass's attributes are inherited. The OnClick event method is augmented to show the value of the new string property in a message box. The second class cShowLabelButton inherits the behavior of cMessageButton, but it also augments the inherited Procedure Set Label method so that the message shown when the button is clicked is the same as the button's label. The Forward Set Label statement is important because, without it, the Set Label method would no longer be able to set the button's label.