7
Oct

ABL Object-oriented Programming


Object-oriented ABL programming enables you
to explicitly model as class files the users, systems, and objects that make up the use
cases of an application. Each class contains definitions for data,
referred to as data members, and the code that implements the behavior of the class
– the constructors, methods, and destructor. The data members can be ABL primitive types,
temp-tables, datasets, and references to user defined types. A class can have one or more constructors
that are used to create instances of the class. The methods of the class are similar to internal
procedures and are used to access the data members and provide the behavior of the class. The optional destructor performs a memory
cleanup when an instance of the class is deleted. An instance of a class is an in-memory object
that contains values for the data members. There can be several instances of a class
at runtime, each with its own data. ABL supports a number of key object-oriented
programming features including inheritance, encapsulation, and interfaces. Classes can inherit data and methods from
other classes. Inheritance promotes code reuse. You can use inheritance to implement a hierarchy
of data and behavior where some or all of the data and methods of the super class are
inherited by the derived classes. Encapsulation is a way of restricting access
to the data and methods of a class. Data members and methods can be defined as
private, protected, or public. Private data members and methods can only
be accessed within the class in which they are defined. Protected data members and methods can be
accessed by derived classes in the inheritance hierarchy. Public data members and methods can be accessed
anywhere in your application. ABL supports standardization of code using
interface classes that define public data members and methods that a set of classes
implement. Classes that implement an interface class
contain their own code for the methods defined in the interface class. Developer Studio provides wizards to help
you easily create classes, data members, and methods. Here is a project called ABL OOP that we have
already created. Because we want our application to access
data from the Sports3000 database, we have connected our project to the database. The New ABL Class wizard helps us define an
ABL class. We start the wizard in the workspace folder
where we want to create the ABL class file. In this case, it is the OrderSystem folder
under src. In the wizard, the package is automatically
set to OrderSystem. Let’s create a Customers class that displays
a customer’s data from the database. We specify the class name. As a best practice, we select the method stubs
for the default constructor and destructor. In addition, we retain the default error-handling
generated by the wizard. When the New ABL Class wizard ends, the class
file is created in the OrderSystem folder and opens in the editor. The first data member that we want to add
to the Customers class is the ttCustomer temp-table. ttCustomer is defined in the ttCustomer.i
file located in the Include folder under src. In our class file we add an include statement
for ttCustomer. Next, we will use the Add Property Wizard
to add another data member, the numCustomers property, that we will later set to the number
of customers in the temp-table. To create the property, we place the cursor
before the include statement and right-click to select Source>Add Property. We enter the name of the property as numCustomers
and ensure that the property Modifiers is set to public, data type is integer, get modifier
is public, and set modifier is private. When the ABL Property wizard ends, the generated
property code is inserted into our class file. Next, we will add the getCustomer() method
to the Customers class using the Add Method Wizard. We place the cursor after the constructor
and right-click to select Source>Add Method. We enter the name of the method as getCustomer
and ensure that the Modifiers is set to public and the return type is void. When the wizard ends, the generated method
code is inserted. Next, we add code to the constructor to populate
the ttCustomer temp-table from the database and increment the numCustomers data member
value. Now, we add an input parameter pCustNum to
the getCustomer() method and add code to find a customer from the ttCustomer temp-table
based on the value of pCustNum and then display the customer number and customer name. Now, let’s test our class. An ABL application can contain both object-oriented
and procedural code. We test our class using a procedure, testCustomer.p,
that creates an instance of the Customers class and accesses the numCustomers public
data member and the getCustomer() public method. Our test procedure is located in a Test project
with the same folder structure as the ABL OOP Project. The Test project has the same database connection
as the ABL OOP project and its PROPATH is set to the src and bin folders of the ABL
OOP project. Let’s look at the code in our test procedure:
• The using statement specifies the package and class name. • The variable CustomersInstance will hold
a reference to an instance of the Customers class. • We create an instance of the Customers
class using the new operator and assign it to the CustomersInstance variable. • We use the instance to call the getCustomer()
method and access the numCustomers data member. When we finish, we delete the instance. Now, let’s run the test procedure. As you can see, our Customers class behaves
as expected. You have now learned about the object-oriented
capabilities of ABL. To learn more, take the course, Introduction
to Object-oriented Programming.

Tags: , , , ,

One Comment

  • Remotos Administrativos Sucahersa says:

    this video doesnt explain anything, and voice is boring , and the speed she takes to each "chapter" is fast, u should RE-DO your tutorials so maybe some people start using your tool.

    https://trends.google.com.mx/trends/explore?q=%2Fm%2F043fdy,%2Fm%2F07sbkfb,%2Fm%2F05z1_,%2Fm%2F0jgqg

Leave a Reply

Your email address will not be published. Required fields are marked *