|Navigation: Language Reference > 5 - Declaration Attributes > Variable and Entity Attributes >====== PROTECTED (set variable private to a CLASS or derived CLASS) ======|
The PROTECTED attribute specifies that the variable on which it is placed is visible only to the PROCEDUREs declared within the same CLASS structure (the methods of that CLASS) and any CLASS derived from the CLASS in which it is declared. This encapsulates the data from any code external to the specific CLASS and its dereived CLASSes.
The purpose of the PROTECTED attribute is to provide a level of encapsulation between public and PRIVATE. All PROTECTED data and methods are available for use within their own CLASS and derived CLASSes, but not available to any code outside those specific CLASSes.
You could think of these as “semiprivate”.
PublicVar LONG !Declare a Public variable
ProtectedVar LONG,PROTECTED !Declare a Protected variable
BaseProc PROCEDURE(REAL Parm) !Declare a Public method
TwoClass OneClass !Instance of OneClass
TwoClass.PublicVar = 1 !Legal assignment
TwoClass.ProtectedVar = 1 !Legal assignment, illegal if PRIVATE
OneClass.BaseProc PROCEDURE(REAL Parm)
SELF.ProtectedVar = Parm !Legal assignment
TwoClass.ProtectedVar = 1 !Legal assignment