Statement DEFERRED Foundation
Declares a method for an abstract class.
DEFERRED [CLASS] METHOD <MethodName>
The DEFERRED attribute makes it possible to declare a method without implementing it in the class. A DEFERRED method must be implemented later in a sub-class where it must be declared again (without this attribute).
A class which has DEFERRED methods cannot be instantiated (no objects can be created for this class). This is called an "abstract class". Abstract classes define the structure for sub-classes which have methods of the same name but with different implementation (polymorphism). Abstract classes normally are used when it is known WHAT kind of functionality must be implemented in sub-classes without knowing HOW the implementation will be.
// The example uses three classes to demonstrate a context
// in which DEFERRED methods are useful. An abstract Income()
// class calculates 'net income' as 'total income minus tax'.
// Taxes are calculated in the DEFERRED method :tax().
// Although :tax() is not implemented in the Income() class,
// this method is called from :netIncome() in the same class.
// At this level it is known WHAT must be calculated (taxes),
// but it is unknown HOW to calculate taxes for two different
// countries (US, Germany). The HOW is dealt with in the two
// sub-classes: IncomeGer() and IncomeUS().
// The output of ProcName() and ::className() helps to
// understand inheritance.
CLASS Income
PROTECTED:
VAR nIncome
EXPORTED:
INLINE METHOD init( nIncome )
RETURN ::nIncome := nIncome
INLINE METHOD netIncome // Calculate net income
? ProcName(), ::className()
RETURN ::nIncome - ::tax()
DEFERRED METHOD tax
ENDCLASS
***************************
CLASS IncomeGer FROM Income
EXPORTED:
INLINE METHOD tax // German tax
LOCAL nTaxRate
? ProcName(), ::className()
IF ::nIncome < 50000
nTaxRate := .35
ELSE
nTaxRate := .45
ENDIF
RETURN nTaxRate * ::nIncome
ENDCLASS
**************************
CLASS IncomeUS FROM Income
EXPORTED:
INLINE METHOD tax // US tax
LOCAL nTaxRate
? ProcName(), ::className()
IF ::nIncome < 25000
nTaxRate := .15
ELSE
nTaxRate := .25
ENDIF
RETURN nTaxRate * ::nIncome
ENDCLASS
**************
PROCEDURE Main
LOCAL oDM := IncomeGer():new( 55000 )
LOCAL oUS := IncomeUS ():new( 55000 )
? oDM:netIncome()
? oUS:netIncome()
RETURN
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.