ABL allows you to override properties in a subclass, whether overriding a property defined in ABL or .NET super classes (.NET overridable properties are defined with the virtual modifier). Properties that are not overridable can be marked as FINAL. For more information on the syntax, see the DEFINE PROPERTY statement.

The following rules apply when overriding ABL properties:
  • The overriding property in the subclass must have the same data type, extent size, and NO-UNDO setting, as the property in the super class.
  • The OVERRIDE modifier is not allowed in interfaces or for STATIC, ABSTRACT, or PRIVATE properties.
  • A property defined as FINAL cannot be overridden.
  • The overriding property in the subclass cannot have a more restrictive access mode than the property in the super class. For example, a PROTECTED subclass property cannot override a PUBLIC super class property. This rule applies to the property itself and the specified accessors (GET/SET).
  • The overriding property in the subclass must have the same accessors (GET/SET) as the property in the super class.

    If the property in the super class has both a GET and SET accessor with implementation code, then the overriding property in the subclass must also have both GET and SET accessors (with or without implementation code or with SUPER).

    If the property in the super class provides only one of the GET/SET accessors, then the overriding property in the subclass is only required to provide that one accessor (with or without implementation code or SUPER).

    CAUTION: If you set the property inside the GET accessor, or get the property inside the SET accessor, or the property is accessed via a method call that is called from within one of the property accessors, the SET or GET accessor is executed again, the same way it would when the property was accessed from outside the corresponding accessor. Therefore, caution needs to be taken to avoid an infinite loop. The same occurs when referencing SUPER:property from within the accessors; it is seen as an external access and any GET or SET accessor in the super class is called.
The following rules apply when overriding .NET properties:
  • The data types of the subclass and super class properties must be compatible.
  • The overriding subclass property cannot have a more restrictive access mode than the property in the super class. For example, if the super class property is PUBLIC, then the subclass overriding property cannot be marked PROTECTED. This rule applies to the property itself and the specified accessors (GET/SET).
  • You can override a property that is marked virtual as long as it is not marked sealed lower in the hierarchy.

For more information, see Override .NET virtual properties in Use .NET Classes in ABL Applications.

Example

The following example illustrates how to override a property. It shows how you can make the property less restrictive (from PROTECTED to PUBLIC), and shows that you can have implementation code (body) for the accessors. The SET accessor in the overriding property also uses the SUPER system reference to access the property in the super class.
CLASS class1:
  DEFINE PROTECTED PROPERTY myProp AS INT GET. SET.
END CLASS.
CLASS class2 INHERITS class1:
  DEFINE PUBLIC OVERRIDE PROPERTY myProp AS INT
  GET SUPER.
  SET(INPUT pValue AS INT).
    /* default value to 10 if smaller */
    IF pValue < 10 THEN
      pValue = 10.
    SUPER:myProp = pValue.
  END SET.
END CLASS.