Statement CLASS METHOD (Implementation) Foundation
Prefaces the actual code for a class method.
CLASS METHOD [<ClassName>:] <MethodName> [( [<Parameters,...>] )]
When the declaration CLASS METHOD is outside the class declaration (outside the CLASS...ENDCLASS statements), it introduces the program code for a declared class method. Class methods are programmed like procedures or user defined functions, but they are called somewhat differently. The class object must first be created by a call to the class function. The name of a method is sent to this class object as a message using the send operator which is the colon (:). The class object then executes the source code of the class method.
If an instance of a class receives the message <MethodName>, it forwards this message on to the class object which executes the class method. An instance (object) is produced by the method :new() of the class object.
Just like functions and procedures, methods can receive arguments whose values are assigned to the variables declared in the parameter list <Parameters,...>. These variables are LOCAL to the method and are only visible within the code of the method. A special feature of methods (as opposed to functions) is the LOCAL variable self, which implicitly exists within each method. It always references the object executing the method. The variable self can neither be explicitly declared within methods nor can it have a value assigned to it.
Instead of using the name of the implicit variable self:, the operator :: can be used. The operator :: is an abbreviation for self: and can be used to access class variables or call class methods.
As with functions and procedures, the source code of a class method is closed by the RETURN statement and the object returns the RETURN value. When a method has no other meaningful RETURN value, self should be returned. This allows a chained set of messages to be sent to the class object (for example, object:method1():method2():method3()).
Each class has an implicit class method :initClass(). If this method is declared and implemented, it is executed automatically after the call to the class function. The method :initClass()is used to initialize member variables of the class object.
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.