Define a class that uses an interface class
- Last Updated: August 17, 2021
- 2 minute read
- OpenEdge
- Version 12.2
- Documentation
Define a class that uses an interface class
When you define a class that uses an interface class, it will have the same data member names and method names with parameters as the interface class.
Here is an example. Suppose you created a class named MobileApp based on the IProduct interface class using the New ABL Class
wizard. The wizard generates the following starter code for you and opens it in the
editor.
using Progress.Lang.*.
using Inventory.IProduct.
using Inventory.Item.
block-level on error undo, throw.
class Inventory.MobileApp implements IProduct:
{include/Items.i}
method public void AddItem( input pItem as Item ):
undo, throw new Progress.Lang.AppError("METHOD NOT IMPLEMENTED").
end method.
method public Item GetItem( input pItemCode as character ):
undo, throw new Progress.Lang.AppError("METHOD NOT IMPLEMENTED").
end method.
method public integer NumberItems( ):
undo, throw new Progress.Lang.AppError("METHOD NOT IMPLEMENTED").
end method.
end class.
When you define a class that uses an interface class, it must have the same data member names and method names with parameters as the interface class. You cannot change the definitions of any of the methods from the interface class. All you can change is the body of the code within the methods.
You do not have to write code for the bodies of all the methods defined in the interface class, but they must be in the class, at least with an empty method body. In addition, you can add any data members or methods to the class that will help implement the behaviors of the class.
Here is an example of a MobileApp class
based on the IProduct interface class. Notice that we
added a data member NativeOS to represent the operating
system for a class instance. We provided implementations for two methods AddItem() and GetItem().
We did not provide an implementation for the NumberItems()
method but its definition remains in the class.
using Progress.Lang.*.
using Inventory.IProduct.
using Inventory.Item.
block-level on error undo, throw.
class Inventory.MobileApp implements IProduct:
{include/Items.i}
define public property NativeOS as character no-undoget.
set.
method public void AddItem( input pItem as Item ):
create ttItem.
// copy data from pItem to ttItem
end method.
method public Item GetItem( input pItemCode as character ):
find ttItem where ItemCode = pItemCode no-error.
//return the reference to the item object in the ttItem record
end method.
method public integer NumberItems( ):
new Progress.Lang.AppError("METHOD NOT IMPLEMENTED").
end method.
end class.
For more information, see Comparison with procedure-based programming persistent procedures.