INTERFACE Verb

Syntax

INTERFACE accesslevel {STATIC} interfacename {EXTENDS interfacelist}

Description

In BBj 6.0 and higher, the INTERFACE verb marks the beginning of a Custom Object interface definition, which must end with an INTERFACEEND verb.

Parameter

Description

accesslevel

The interface access level must be specified, and must be either PUBLIC, or PRIVATE, or PROTECTED .

A PRIVATE interface is only visible to code within the same physical file.

A PUBLIC interface can be accessed from code in other files.

A PROTECTED interface (BBj 21.0 and higher) can only be accessed from programs within the same directory as the class or interface declaration.

STATIC The optional STATIC clause indicates that the class or interface definition should be shared between interpreters using the same SSCP. All custom object dependencies of a STATIC class or interface also need to be STATIC. As part of this, static fields of the class will be shared between the interpreters.

interfacename

The interface name must begin with a letter or underscore and can contain any combination of letters, numbers and underscores.

EXTENDS interfacelist

The optional EXTENDS clause indicates that this interface incorporates the methods of one or more other comma-delimited Custom Object interfaces. Each of these can be:

  • The name of an interface whose definition exists in the same program file

  • The name of an interface specified in a USE statement in the same program file.

  • A fully qualified interface name in the form ::filename::interfacename.

Notes

All BBj Custom Object names (interface name, class name, method name, field name) are case-sensitive.

The INTERFACE verb must be the only statement on the line (with one exception: it can end with a ; REM comment).

If a program with an INTERFACE verb does not contain an INTERFACEEND verb on a subsequent line, the INTERFACE verb is a syntax error.

The INTERFACE verb may not be nested within any other CLASS, METHOD, or INTERFACE.

The interface definition (the area between INTERFACE and INTERFACEEND) can only contain METHOD statements. Any other statements or labels contained within the interface definition are unreachable and will not be executed.

An interface can extend one or more Interfaces, but cannot implement another interface or extend a class.

Since STATIC classes or interfaces are shared by multiple interpreters, starting a new interpreter will not allow you to load a new version of the class or interface if it is changed on disk, assuming that the old version was previously successfully loaded. You may need to restart BBjServices in order to get a new version.

As of BBj 21.0, an interface can contain method bodies. For static methods this will add a static method to the interface. For normal methods this will add a default method implementation so that classes that implement the method are not required to provide their own implementation of the method.

Example

rem ' INTERFACE Verb Example

rem ' Payroll

e1! = new Salaried()
e1!.setID(1)
e1!.setName("Mary Jones")
e1!.setMonthlySalary(5000)
e1!.print()
print "GL Account:",e1!.account()

e2! = new Hourly()
e2!.setID(2)
e2!.setName("John Smith")
e2!.setHourlyRate(15)
e2!.setHoursWorked(168)
e2!.print()
print "GL Account:",e2!.account()

interface public Address
    method public void address()
interfaceend

interface public Pay
    method public void print()
interfaceend

interface public GL
    method public BBjNumber account()
interfaceend

interface public Payable extends Pay, GL
    method public BBjNumber pay()
interfaceend

class public Employee
    field public BBjNumber ID
    field public BBjString Name$
classend

class public Salaried extends Employee implements Payable
    field public BBjNumber MonthlySalary

    method public BBjNumber pay()
        methodret #MonthlySalary
    methodend

    method public void print()
        print "Employee",#getID(),": ",#getName()
        print #pay():"($###,###.00)"
    methodend

    method public BBjNumber account()
        methodret 11111
    methodend

classend

class public Hourly extends Employee implements Payable
    field public BBjNumber HourlyRate
    field public BBjNumber HoursWorked

    method public BBjNumber pay()
        methodret #HourlyRate*#HoursWorked
    methodend

    method public void print()
        print "Employee",#getID(),": ",#getName()
        print #pay():"($###,###.00)"
    methodend

    method public BBjNumber account()
        methodret 22222
    methodend
    
classend

ClosedVersion History

  • BBj 21.0: Added PROTECTED access level.

  • BBj 21.0: Interfaces can now contain method bodies.

  • BBj 6.0: INTERFACE Verb Introduced

See Also

Verbs - Alphabetical Listing

INTERFACEEND Verb

CLASS Verb