-
Notifications
You must be signed in to change notification settings - Fork 0
Quick start
- Class definition
- Instance attributes
- Instantiating objects
- Calling methods
- Deleting objects
- Accessing attributes
- More information
The shortest barebones class definition in objectbatch contains a class header and a class constructor, as follows:
call class %*
%class%
:public-construct --> 1:objectname
call super %*
exit /b
We may declare one or more instance attributes in the constructor method (public-construct) using the following syntax:
:public-construct --> 1:objectname
call super %*
set %self%.myAttr1=something
set %self%.myAttr2=somethingelse
exit /b
Note that we can only declare instance attributes in the constructor after the superclass call, as this will instantiate our object by inheriting from the base object.
To instantiate a new object myobj of type MyClass, we may use the following syntax:
call new myClass myobj construct
The example above constructs a new object myobj of type MyClass and makes sure it is correctly instantiated using the new keyword.
To call a public method of a given class MyClass, for example the constructor method construct, for a given object obj we may use the following syntax:
call MyClass obj construct
If an object is already instantiated, we may use the # syntax below:
call # obj construct
The example above is a shorthand notation that exploits the __class__ attribute of any object to call the correct class method.
To pass input arguments to public methods from outside the class, we may simply use the normal method call syntax and add any extra arguments, as follows:
call Class object method arg1 arg2 ...
To remove a given object obj from the batch environment, we may use the following syntax:
call clear obj
To write a value to an object attribute myAttr for object obj, we may use the following syntax:
set %obj%.myAttr=2
To read the value of an object attribute myAttr for object obj, we may use the following syntax (using delayed expansion):
echo !%obj%.myAttr!
To avoid using delayed expansion, use getattr.
More information can be found in the home page, the quick start page and the examples.