Table of Contents
  A Primer for Using BBj Custom Objects

PDF Format

David Wallwork
Software Architect

uring the last several years, BASIS added a series of enhancements to BBj that provide new functionality ranging from embedded Java to transaction-based commit and rollback; from Web Services that execute BBj applications to new development tools such as the IDE and AppBuilder; from new table or file types to data entry validation. Conspicuously absent from this list was the ability to write object-oriented code as BBj native code without using embedded Java.

BBj Custom Objects
BBj 6.0 introduces a number of new verbs that allow the developer to write classes and objects within a BBj program file, delivering fully object-oriented capability to Business BASIC. Classes defined in BBj are referred to as custom classes and instances of a custom class are referred to as custom objects.

Custom objects in BBj provide a full set of object-oriented features including:

  • Protection levels (private, protected, public)
  • Inheritance structures (extends)
  • Interfaces structures (implements)
  • Strongly-typed parameter lists and return values
  • Multiple constructors
  • Overloaded methods (accepting different parameter lists)
  • Static variables
  • Static methods
  • Variable initialization
  • Variable scope

A Custom Class
Understanding custom classes requires both a general knowledge of object-oriented programming and specific understanding of BBj syntax. Since there is a large body of information already published and readily available about object-oriented programming, we will not discuss the general concepts (see a few of these resources listed at the end of this article). What is important for us to demonstrate in this article is the syntax used in BBj to write an object-oriented program. The following two short examples demonstrate that syntax. A complete syntax definition may be found in the references at the end of this article.

The first example shown in Figure 1 is a simple program that defines a custom class, instantiates an instance of that custom class (instantiates a custom object), and invokes a method on the instance. The output of this program prints hello world to the console.

Figure 1. Sample program helloworld.src that defines a custom class

The second example shown in Figure 2 greets the user in Spanish, English, or French. Next, it prints information about the greeter and about the static value that holds the total number of guests greeted.

Figure 2. Code sample greeter.src that greets users in multiple languages

This small program demonstrates a number of object-oriented concepts and how they are realized in BBj. The reader will notice the use of polymorphic classes (the various child classes of Greeter), static values and static methods (totalGreetingCount), class extension, and protection levels illustrated in Figure 3.

Figure 3. Using polymorphism in BBj

Though these examples assume an understanding of object-oriented programming, many readers may be unfamiliar with this concept. There is an abundance of well-written technical resources available, but BASIS recommends reviewing the sites listed below as a good starting point to learn the basic concepts.

More than any other of the changes in the recent past, the adding of object-oriented programming to BBx technology has the greatest potential to impact the day-to-day development and the way developers build business applications. BBj custom objects can streamline the development process and promote code re-use, resulting in more robust applications getting to market faster than ever before. Truly, adding object-oriented programming takes BBx technology light-years ahead of traditional Business BASIC.

  Download the sample programs referenced in this article

For an overview of how object-oriented programming techniques can help you write modules that are more robust and reusable, see

To learn more about custom objects and how to use them in BBj, refer to and

Table of Contents