version 1.44, 2025/05/05 05:16:34
|
version 1.45, 2025/05/05 12:34:02
|
Line 4944 If you use other M implementations, you
|
Line 4944 If you use other M implementations, you
|
@cindex object-oriented programming |
@cindex object-oriented programming |
@cindex programming, object-oriented |
@cindex programming, object-oriented |
|
|
|
@menu |
|
* Classes:: The organizing concept of object-oriented programming. |
|
* Inheritance:: Making one class derive from another. |
|
* Methods:: Attach code to classes. |
|
* Public and Private Variables:: Determining accessibility. |
|
* Instantiating Objects:: Creating instances of classes. |
|
@end menu |
|
|
|
@node Classes |
@section Classes |
@section Classes |
@subsection Class Overview |
@subsection Class Overview |
|
|
Line 5000 DESTROY(THIS) ;
|
Line 5008 DESTROY(THIS) ;
|
Q |
Q |
@end example |
@end example |
|
|
|
@node Inheritance |
@section Inheritance |
@section Inheritance |
|
|
Every class you create will automatically inherit the methods and functionality of the @code{OBJECT} class, supplied with FreeM. |
Every class you create will automatically inherit the methods and functionality of the @code{OBJECT} class, supplied with FreeM. |
Line 5018 You can achieve runtime polymorphism by
|
Line 5027 You can achieve runtime polymorphism by
|
|
|
Note that the overridden method in the subclass can take a different set or number of arguments than the @emph{formallist} of the superclass method would specify. |
Note that the overridden method in the subclass can take a different set or number of arguments than the @emph{formallist} of the superclass method would specify. |
|
|
|
@node Methods |
@section Methods |
@section Methods |
Class methods are defined as tags with @emph{formallist}s in a class routine, and per the typical FreeM object pattern, must take at least one argument, being @code{THIS} (representing a reference to the object instance being accessed). |
Class methods are defined as tags with @emph{formallist}s in a class routine, and per the typical FreeM object pattern, must take at least one argument, being @code{THIS} (representing a reference to the object instance being accessed). |
|
|
Line 5040 DEFAULT.USER> W MYOBJ.MYMETHOD()
|
Line 5050 DEFAULT.USER> W MYOBJ.MYMETHOD()
|
VALUE |
VALUE |
@end example |
@end example |
|
|
|
@node Public and Private Variables |
@section Public and Private Variables |
@section Public and Private Variables |
|
|
FreeM supports private fields with the @code{:PRIVATE} specifier in the @code{SET} command, enforcing classical object-oriented data encapsulation. The @code{:PUBLIC} specifier is provided for completeness, and is the default. |
FreeM supports private fields with the @code{:PRIVATE} specifier in the @code{SET} command, enforcing classical object-oriented data encapsulation. The @code{:PUBLIC} specifier is provided for completeness, and is the default. |
Line 5062 Either of the following commands will cr
|
Line 5073 Either of the following commands will cr
|
|
|
Attempting to access private fields from outside of the class will raise error condition @code{ZOBJFLDACCV}. |
Attempting to access private fields from outside of the class will raise error condition @code{ZOBJFLDACCV}. |
|
|
|
@node Instantiating Objects |
@section Instantiating Objects |
@section Instantiating Objects |
|
|
To instantiate an object (i.e., create an object from a certain class), you will use the @code{NEW} command as follows: |
To instantiate an object (i.e., create an object from a certain class), you will use the @code{NEW} command as follows: |
Line 5072 NEW MYSTR=$#^%STRING("myString")
|
Line 5084 NEW MYSTR=$#^%STRING("myString")
|
|
|
This will create a local variable called MYSTR of type STRING, and initialize it with the value myString. |
This will create a local variable called MYSTR of type STRING, and initialize it with the value myString. |
|
|
@section Determining Object Class |
@subsection Determining Object Class |
|
|
To determine the class of any FreeM local variable, you will use the @code{$$TYPE()} method: |
To determine the class of any FreeM local variable, you will use the @code{$$TYPE()} method: |
|
|