Interface Declarations

An IDL interface is just a collection of data attributes and methods that define the semantics of the interface. Declaring an interface is another way to create a new data type in IDL, but unlike structs and unions, an interface can have both data members and methods that can be called on objects of its type. An interface is also a name-scoping construct, similar to a module. You can declare an IDL interface and simply include a set of constants that you want associated with that interface name. In this case, you have to specify the interface scope in order to refer to the constants from within other scopes.

An interface consists of the following elements:

// IDL
interface identifier [: inheritance spec] {
     interface body
};

The interface identifier can be any valid IDL identifier. The body of the interface can contain any of the following constructs:

  • A user-defined type (struct, union, typedef, enum)

  • A constant declaration

  • An interface-specific exception declaration

  • Data attributes

  • Methods or operations

We’ve already seen the syntax for the first three of these items in earlier sections of this IDL overview. They become part of an interface simply by being declared within the braces of the body of the interface. In the next few sections, we’ll see how to define interface attributes and methods , and then we’ll look at how inheritance of IDL interfaces works.

Attributes

Attributes are data members that belong to interfaces. To readers familiar with JavaBeans, declaring ...

Get Java Enterprise in a Nutshell, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.