Override properties within a class hierarchy
- Last Updated: September 16, 2021
- 3 minute read
- OpenEdge
- Version 13.0
- Documentation
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 overriding property in the subclass must have the same data type, extent
size, and
NO-UNDOsetting, as the property in the super class. - The
OVERRIDEmodifier is not allowed in interfaces or forSTATIC,ABSTRACT, orPRIVATEproperties. - A property defined as
FINALcannot 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
PROTECTEDsubclass property cannot override aPUBLICsuper 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
GETandSETaccessor with implementation code, then the overriding property in the subclass must also have bothGETandSETaccessors (with or without implementation code or withSUPER).If the property in the super class provides only one of the
GET/SETaccessors, then the overriding property in the subclass is only required to provide that one accessor (with or without implementation code orSUPER).CAUTION: If you set the property inside theGETaccessor, or get the property inside theSETaccessor, or the property is accessed via a method call that is called from within one of the property accessors, theSETorGETaccessor 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 referencingSUPER:propertyfrom within the accessors; it is seen as an external access and anyGETorSETaccessor in the super class is called.
- 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 markedPROTECTED. This rule applies to the property itself and the specified accessors (GET/SET). - You can override a property that is marked
virtualas long as it is not markedsealedlower in the hierarchy.
For more information, see Override .NET virtual properties in Use .NET Classes in ABL Applications.
Example
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.
|
|