Skip to content

Class definition

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

Class definition

A class definition in objectbatch consists of the class header, which contains the code required for the objectbatch class functionality, and class methods, which includes the constructor method that can be used to define instance attributes.

Class header

The bare class header is specified as below:

call class %*
%class%

Superclass

An optional superclass may be specified before the class header to inherit from that superclass. If no superclass is specified, the class automatically inherits from object. For example, to inherit from myClass2, we may add the following line before the class header:

set __super__=myClass2

Constructor

Finally, the constructor and other methods may be defined. The constructor must be a public method. The bare public constructor method with no attributes specified is as follows:

:public-construct
	call super %*
exit /b

Note the call to super inside the construct method, which calls the constructor of the direct superclass. Note that this is required even for classes that only inherit from object, as the object constructor needs to be inherited.

Full class

Using the example code snippets above, a full class definition that inherits from myClass2, specifies one instance attribute a, and defines the public method __dict__ may look like this:

set __super__=myClass2
call class %*
%class%

:public-__dict__
	call super %*
exit /b

:public-construct
	call super %*
	set %self%.a=0
exit /b

More information

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

Clone this wiki locally