[Previous] [Contents] [Next] [IONA Technologies]


Chapter 13
Inheritance


Contents

13.1 Single Inheritance of IDL Interfaces
13.1.1 The Client: IDL Generated Types
13.1.2 Usage from a Client
13.1.3 The Server: IDL Generated Types
13.2 Multiple Inheritance of IDL Interfaces



IDL allows a new interface to be defined by extending the functionality provided by an earlier one (as described in Chapter 4, "The Interface Definition Language"). The new interface inherits or derives from the first. IDL also supports multiple inheritance, allowing an interface to have several immediate base interfaces.

13.1 Single Inheritance of IDL Interfaces

As an example of single inheritance, consider extending the bank account example of Chapter 6, with checking (or current) accounts:

The new interface CheckingAccount derives from interface Account. We have also added a new operation to interface Bank, to manufacture CheckingAccounts.1

13.1.1 The Client: IDL Generated Types

As in previous chapters, we will assume that this IDL definition has been compiled with the command:

OrbixWeb maps IDL interfaces to Java interfaces. The IDL interface inheritance hierarchy maps directly to the Java interface inheritance hierarchy, as shown in Figure 13.1:

Figure 13.1: IDL and corresponding Java hierarchies

The interface Account maps to the following Java interface type:

The IDL interface CheckingAccount maps to:

The IDL compiler also generates Java implementation classes for these Java interfaces2. For each Java interface, the corresponding class implements the methods defined in the interface. Each method implementation provides client proxy functionality for the appropriate IDL operation. The Java class also implements static _bind() and _narrow() methods.

IDL interface inheritance maps directly to the inheritance hierarchy of the generated Java interfaces, but does not map to the generated Java classes for those interfaces. Therefore, each Java class which implements an IDL generated Java interface must implement both the methods of that interface and the methods of all interfaces from which it inherits. Of course, this is an internal OrbixWeb implementation detail and does not impose any additional burden on the programmer.

This feature facilitates the mapping of IDL multiple inheritance to Java, as discussed in section 13.2.

The generated Java class which implements the _AccountRef interface is:

The generated Java class which implements the _CheckingAccountRef interface is:

13.1.2 Usage from a Client

A client can proceed to manipulate CheckingAccounts in a similar way to the Accounts of Chapter 6:

For information on narrowing object references in an inheritance hierarchy, see section 5.9.1.

13.1.3 The Server: IDL Generated Types

On the server side, the IDL compiler generates the Java interface _CheckingAccountOperations, which defines the methods that a server class must implement in order to support IDL interface CheckingAccount. This Java interface inherits from type _AccountOperations, which serves a similar purpose for IDL type Account. The manner in which a Java class implements the _CheckingAccountOperations method depends on the approach to IDL interface implementation in use.

The BOAImpl Approach

The IDL compiler generates class _boaimpl_CheckingAccount to support the BOAImpl approach to IDL interface implementation. This abstract class implements Java interface _CheckingAccountOperations and redefines the methods of that interface (and all interfaces from which it inherits) as abstract methods.

In order to implement IDL interface CheckingAccount using the BOAImpl approach, the programmer defines a Java class which inherits from class _boaimpl_CheckingAccount and implements the methods defined in this class. This has important consequences for the reusability of implementation classes.

Java does not support multiple inheritance of classes, so if an existing class implements a subset of the abstract methods defined for type CheckingAccount (for example, an existing class implements IDL type Account), it cannot be reused in the CheckingAccount implementation class. The CheckingAccount implementation class must directly implement all the operations of IDL interface CheckingAccount and all interfaces from which it inherits. This restriction severely limits the flexibility of the BOAImpl approach.

Interfaces Account and CheckingAccount could be implemented as follows:

The TIE Approach

Using the TIE approach to IDL interface implementation, the CheckingAccount implementation class simply needs to implement Java interface _CheckingAccountOperations; that is, there is no implicit inheritance requirement imposed on the implementation class. This has the advantage of making the implementation programmer free to inherit from any existing class which may implement a subset of the required methods.

For example, if existing class AccountImplementation implements the methods defined in interface _AccountOperations, then class CheckingAccountImplementation could be coded as follows:

The TIE approach allows the programmer to take advantage of the re-use characteristics of object-oriented programming.

13.2 Multiple Inheritance of IDL Interfaces

IDL supports multiple inheritance of interfaces. A (slightly contrived) example is:

Java also supports multiple inheritance of interfaces, but does not support multiple inheritance of classes. As in the case of single inheritance, the inheritance hierarchy of IDL interfaces maps directly to an identical inheritance hierarchy of Java interfaces which define client-side functionality. For example, the interface hierarchy in the above definition maps as follows:

Figure 13.2: IDL and corresponding Java hierarchies

The inheritance hierarchy does not map to the Java classes which implement the generated Java interfaces. Consequently, each generated Java class implements the methods of the corresponding Java interface and of all interfaces from which it inherits. In this way, a client which holds _PremiumAccountRef object reference can invoke all inherited operations (from _AccountRef, _CheckingAccountRef, and _DepositAccountRef) directly on that reference.

On the server side, the implementation class requirements are identical to those for the single inheritance case. Using the BOAImpl approach, the implementor of type PremiumAccount must inherit from class _boaimpl_PremiumAccount and directly implement all methods for interface PremiumAccount and all types from which it inherits. Using the TIE approach, the implementation class must implement Java interface _CheckingAccountOperations, but may inherit implementation methods from an existing class. However, the absence of multiple inheritance support in Java implies that a multiple inheritance hierarchy of IDL interfaces can never map directly to the implementation classes for those interfaces.

Note that IDL forbids any ambiguity arising due to name clashes of operations and attributes when two or more direct base interfaces are combined. That is, it is illegal for an IDL interface to inherit from two or more interfaces with the same operation or attribute name. It is, however, legal to inherit two or more constants, types or exceptions with the same name from more than one interface, however every use of these must be qualified with the name of the interface (that is, an IDL scoped name must be used).



1 We could have also derived from the interface Bank, for example, to produce a new interface, say, commercialBank, which supports the newCheckingAccount operation. However, this would have made the example a little more difficult to explain.



2 The implementation of Java interfaces in client-side generated code supplies proxy functionality to client applications–it should not be confused with the implementation of IDL interfaces in OrbixWeb servers.



[Roadmap] [Introduction] [GS: Applications] [GS: Applets]
[IDL] [Mapping] [Programming OrbixWeb] [Publishing Objects] [Retrieving Objects] [IIOP]
[Running Clients] [Running Servers] [Exceptions] [Inheritance] [Callbacks] [Contexts]
[API Configuration] [TypeCode] [Any] [DII] [IR] [Filters] [Smart Proxies] [Loaders] [Locators]
[Index]