Coding attribute (get and set) methods
You can provide access to an instance variable X
from
outside the class in which X
is defined by coding
accessor (get) and mutator (set) methods for X
.
About this task
Instance
variables in COBOL are private: the class that defines
instance variables fully encapsulates them, and only the instance
methods defined in the same OBJECT
paragraph can
access them directly. Normally a well-designed object-oriented application
does not need to access instance variables from outside the class.
COBOL does not directly support the concept of a public instance variable as defined in Java™ and other object-oriented languages, nor the concept of a class attribute as defined by CORBA. (A CORBA attribute is an instance variable that has an automatically generated get method for accessing the value of the variable, and an automatically generated set method for modifying the value of the variable if the variable is not read-only.)