User Tools

Site Tools


protected_set_variable_private_to_a_class_or_derived_class_.htm
Navigation:  Language Reference > 5 - Declaration Attributes > Variable and Entity Attributes >====== PROTECTED (set variable private to a CLASS or derived CLASS) ====== Previous pageReturn to chapter overviewNext page

PROTECTED

blk2blue.jpg

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”.

Example:

OneClass  CLASS,MODULE('OneClass.CLW'),TYPE

PublicVar     LONG                  !Declare a Public variable

ProtectedVar  LONG,PROTECTED        !Declare a Protected variable

BaseProc      PROCEDURE(REAL Parm)  !Declare a Public method

         END

TwoClass  OneClass                  !Instance of OneClass

CODE

TwoClass.PublicVar = 1             !Legal assignment

TwoClass.ProtectedVar = 1          !Legal assignment, illegal if PRIVATE

!OneClass.CLW contains:

MEMBER()

MAP

SomeLocalProc  PROCEDURE

END

OneClass.BaseProc  PROCEDURE(REAL Parm)

CODE

SELF.ProtectedVar = Parm           !Legal assignment

SomeLocalProc  PROCEDURE

CODE

TwoClass.ProtectedVar = 1          !Legal assignment

See Also:

CLASS

protected_set_variable_private_to_a_class_or_derived_class_.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1