Navigation: Language Reference > 5 - Declaration Attributes > Variable and Entity Attributes >====== PRIVATE (set variable private to a CLASS module) ====== | |
PRIVATE
The PRIVATE attribute specifies that the variable on which it is placed is visible only to the PROCEDUREs defined within the source module containing the methods of the CLASS structure (whether members of the CLASS or not). This encapsulates the data from other CLASSes.
PRIVATE is also valid when used with static (threaded or non-threaded) variables outside of a CLASS structure. If a static variable is declared with the PRIVATE attribute, the compiler generates it without a public external name. Hence, it can only be used by procedures defined in the same source module.
The PRIVATE attribute is also allowed for TYPE declarations.
Example:
OneClass CLASS,MODULE('OneClass.CLW'),TYPE
PublicVar LONG !Declare a Public variable
PrivateVar LONG,PRIVATE !Declare a Private variable
BaseProc PROCEDURE(REAL Parm)!Declare a Public method
END
TwoClass OneClass !Instance of OneClass
CODE
TwoClass.PublicVar = 1 !Legal assignment
TwoClass.PrivateVar = 1 !Illegal assignment
!OneClass.CLW contains:
MEMBER()
MAP
SomeLocalProc PROCEDURE
END
OneClass.BaseProc PROCEDURE(REAL Parm)
CODE
SELF.PrivateVar = Parm !Legal assignment
SomeLocalProc PROCEDURE
CODE
TwoClass.PrivateVar = 1 !Legal assignment
See Also: