Lesson 10 | Attributes |
Objective | Describe the mapping of IDL interface attributes in Java. |
Mapping IDL Interface Attributes
Attributes in IDL are thought of as public instance variables of the remote object.
However, access to variables commonly differs from method calls in that accessing variables is accessing memory locations in the address space as directly as possible in the language.
Because the remote object is, by definition, in a different address space, it cannot map to instance variables in Java.
Accessors and mutators need to be created for each attribute so that the stub can turn around and call the server object remotely for the appropriate values.
Accessor and mutator:
The object-oriented properties of encapsulation and information hiding imply that variables internal to an object should not be accessed directly.
It is common practice to create a pair of methods, one to return the value of the variable (the accessor or getter method) and one to set the value of the variable (the mutator or setter).
Getter and setter
For each attribute, two overloaded methods in the stub and skeleton are created: one getter and one setter.
In cases of read-only
attributes, only the getter is generated. Both have the same name as the attribute name in the IDL. The Slide Show below illustrates how attributes work.