Best Practices - Aparent Class Property

The purpose of this document is to provide best practices to use the APARENT class property, which gives access to the instance referencing the class you are working on.

If a child class is used by different parent classes, refering to the parent class in the script associated with the child class can be risky. You could test this.APARENT.objecttype, but the code would still depend on the parent class evolution, making it unpredictable.

The general rule is the following: if the control or initialization of a property in a child instance does not depend on the parent, place the code at the child class level. Otherwise, place it at the parent class level.

Example:

Suppose you have an "ORDER" class, a "DELIVERY" class, and a "LINE" class.

  • The "ORDER" header contains properties CODE, NAME, DATEORD, and LINES().
  • The "DELIVERY" header contains properties CODE, NAME, DATEDEL, and LINES().
  • The "LINES" structure is the same in both cases: it contains properties DATELINE, QUANTITY, and ITEM.

The correct method for the script associated with the "ORDER" class is as follows:

$PROPERTIES
 Case CURPRO
   When "LINES.DATELINE" : Gosub DATELINE
   ...
 Endcase
Return
$DATELINE
 Case ACTION
   When "INIT" : Gosub INIT_DATELINE
   ...
 Endcase
Return
$INIT_DATELINE
  this.DATELINE=this.APARENT.DATEORD
Return

The correct method for the script associated with the "DELIVERY" class is as follows:

$PROPERTIES
 Case CURPRO
   When "LINES.DATELINE" : Gosub DATELINE
   ...
 Endcase
Return
$DATELINE
 Case ACTION
   When "INIT" : Gosub INIT_DATELINE
   ...
 Endcase
Return
$INIT_DATELINE
  this.DATELINE=this.APARENT.DATEDEL
Return