インタフェース定義では,オペレーションに加えて,インタフェースの一部分として属性を定義できます。デフォルトでは,すべての属性はread-writeであり,IDLコンパイラは属性の値を設定するメソッドと属性の値を取得するメソッドの二つのメソッドを生成します。また,read-only属性も指定できますが,この場合は読み込みメソッドだけが生成されます。
IDLサンプル11-2は,read-write属性とread-only属性という二つの属性を定義するIDL指定を示しています。コードサンプル11-13は,IDLで宣言されたインタフェース用に生成されたオペレーションクラスを示しています。
interface Test {
attribute long count;
readonly attribute string name;
};
class Test : public virtual CORBA::Object {
. . .
// Methods for read-write attribute
virtual CORBA::Long count();
virtual void count(CORBA::Long __count);
// Method for read-only attribute.
virtual char * name();
. . .
};
public interface TestOperations {
// Methods for read-write attribute
public int count ();
public void count (int count);
// Method for read-only attribute.
public java.lang.String name ();
}