Skip to content

Methods

Richard Baltrusch edited this page Mar 9, 2021 · 4 revisions

Methods

Public method

To declare a public method, such as the constructor, the method name needs to be prefixed with the prefix -public. For example, a public class constructor method may be defined as below:

:public-construct
    call super %*
exit /b

The declared public method can then be called using the following syntax for an instantiated objected obj:

call # obj construct

Private method

To declare a private method, the method name should not start with the -public prefix. This means that the method can only be called from outside the class definition. For example, we may define a private method myPrivateMethod:

:myPrivateMethod
    echo this is a private method!
exit /b

This private method can not be called outside the class, but it can be called normally from inside another class method using the following syntax:

:public-somePublicMethod
    call :myPrivateMethod %*
exit  /b

Input arguments

An unlimited amount of input arguments may be passed to public methods from outside the class.

Constructor argument passing

To pass input arguments to the constructor, we may use the following syntax:

call myClass obj construct 23

In the example above, we are passing the value 23 as an input argument to the constructor. The constructor may then use that passed input argument, for example, to initialize an instance attribute z:

:public-construct
    call super %*
    set %self%.z=%~3
exit /b

Note that we need to use the %~3 syntax (third argument) to access the passed argument (23), as the first and second arguments for any public method are taken up by the names of the object and the called method, respectively.

Public method argument passing

To pass input arguments to a normal public method for an instantiated object obj, we may use the following syntax:

call # obj methodname hello

In the example above, we are passing the input argument hello to the method methodname. The method may once again access that input argument by using the %~3 syntax.

Dynamic method definition

Method definitions outside the class definition are not possible in objectbatch.

More information

More information can be found in the home page, the quick start page and the examples.