Learning Xbasic - Classes
Learn how to create Xbasic classes in these articles that discuss everything from the basics of creating a class, inheritance, and testing classes.
- Xbasic with Classes
You should find the new Xbasic classes to have most of the capabilities of classes in C#, Java, and Visual Basic .NET without being too complex to understand. In general, object-oriented programming and classes attempt to make software more robust and reusable. They do this in a number of ways.
- Xbasic Class Syntax
The syntax in this article describes Xbasic classes in Backus-Naur Form (BNF).
- Designing an Xbasic Class
Designing a class well takes a certain amount of art and skill, but is not really that difficult. The basic steps are
- Implementing an Xbasic Class
Following the design logic discussed in Designing an Xbasic Class, we can implement the beginning of an Xbasic class to call a stored procedure as follows. Note that not all the desired features have been implemented, as discussed in the "to do" comments. In the first section, we define the class with global scope, and the two member properties. Notice that one property is completely protected, and the other has mixed visibility. We could have omitted the global scope modifier, as it is the default.
- Testing and Using an Xbasic Class
In general, it's good to test Xbasic code of any sort first in an Interactive window. When you find good sequences for testing, you can copy them into Xbasic scripts, along with notes about the expected output. Your Xbasic scripts can easily include code to set up and tear down test databases.
- Subclasses and Inheritance
In Designing an Xbasic Class we offhandedly asked "Do we need 14 subclasses, one for each different database API?" and answered "It's one way to go." Let's explain what subclasses are, and why are they useful. Subclasses are classes derived from a base class. In Xbasic, that is done with the INHERITS keyword:
- Classes in Namespaces
In Implementing an Xbasic Class we defined a class: