Summary:
See also: Variables, Functions.
Classes and objects introduce the benefits of OOP programming in Genero BDL.
Classes are templates which define methods that interact with a specific program object instantiated at runtime, allowing you to change the appearance or behavior of the object.
Classes are grouped into packages. Some packages are build-in in the runtime system, other packages are available as extension libraries and must be imported to be available to the program.
DEFINE obj package.classname
CALL package.classname.method( parameter [,...] ) [RETURNING
...]
LET variable = package.classname.method( parameter
[,...] )
CALL obj.method( parameter [,...] ) [RETURNING
...]
LET variable = obj.method( parameter [,...]
)
There are two types of methods: Class Methods and Object Methods. Methods can be invoked like global functions, by passing parameters and/or returning values.
Class Methods - you call these methods using the class identifier (package name + class name) as the prefix, with a period as the separator.
01
CALL ui.Interface.refresh()
The method refresh()
is a Class Method of the Interface class, which is
part of the ui package.
Object Methods - To use these methods, the object must exist. After an object has been created, you can call the Object Methods in the class by using the object variable as a prefix, with a period as the separator:
01
LET b = n.getDocumentElement()
The method getDocumentElement()
is an Object Method of the class to which the
n object belongs.
To handle an object in your program, you
O1
DEFINE n om.DomDocument, b DomNode02
LET n = om.DomDocument.create("Stock")03
LET b = n.getDocumentElement()
The object n is instantiated using the create()
Class Method of the
DomDocument class. The object b is instantiated using the
getDocumentElement()
Object method of the DomDocument class. This
method returns the DomNode object that is the root node of the DomDocument
object n.
The object variable only contains the reference to the object. For example, when passed to a function, only the reference to the object is copied onto the stack.
You do not have to destroy objects. This is done automatically by the runtime system for you, based on a reference counter.
01
MAIN02
DEFINE d om.DomDocument03
LET d = om.DomDocument.create("Stock") -- Reference counter = 105
END MAIN -- d is removed, reference counter = 0 => object is destroyed.
You can pass object variables to functions or return them from functions. Objects are passed by reference to functions. In the following example, the function creates the object and returns its reference on the stack:
01
FUNCTION createStockDomDocument( )02
DEFINE d om.DomDocument03
LET d = om.DomDocument.create("Stock") -- Reference counter = 104
RETURN d05
END FUNCTION -- Reference counter is still 1 because d is on the stack
Another part of the program can get the result of that function and pass it as a parameter to another function.
01
MAIN02
DEFINE x om.DomDocument03
LET x = createStockDomDocument( )04
CALL writeStockDomDocument( x )05
END MAIN06 07
FUNCTION createStockDomDocument( )08
DEFINE d om.DomDocument09
LET d = om.DomDocument.create("Stock")10
RETURN d11
END FUNCTION12 13
FUNCTION writeStockDomDocument( d )14
DEFINE d om.DomDocument15
DEFINE r om.DomNode16
LET r = d.getDocumentElement()17
CALL r.writeXml("Stock.xml")18
END FUNCTION
Built-in packages implement classes that are useful for any Genero program, as for example string manipulation classes.
Built-in packages are part of the runtime system library and do not need any import instruction to be available.
Classes | Purpose |
Application | Provides an interface to the application internals |
Channel | Provides basic read/write functionality (files/communication) |
StringBuffer | Allows manipulation of character strings |
StringTokenizer | Allows parsing of strings to extract tokens |
TypeInfo | Provides serialization of program variables |
Classes | Purpose |
Interface | Provided to manipulate the user interface |
Window | Provides an interface to the Window objects |
Form | Provides an interface to the forms used by the program |
Dialog | Provides an interface to the interactive instructions |
ComboBox | Provides an interface to the ComboBox formfield view |
Classes | Purpose |
DomDocument | Provides methods to manipulate a DOM data tree |
DomNode | Provides methods to manipulate a node of a DOM data tree |
NodeList | Holds a list of selected DomNode objects |
SaxAttributes | Provides methods to manipulate XML element attributes |
SaxDocumentHandler | Provides methods to write an XML filter |
XmlReader | Provides methods to read and process a file written in XML format |
XmlWriter | Provides methods to write XML documents to different types of output |
Packages that must be imported are typically implementing specific utility classes that are not needed by regular Genero programs.
In order to use a class of an extension library package, you must import the package library in your program.
Classes | Purpose |
Math | Provides an interface for mathematical functions |
Classes | Purpose |
Path | Provides functions to manipulate files and directories on the machine where the BDL program executes |