PreviousNext

Finding Out if an Interface is Supported

One of the most common reasons to find out if an interface is supported is to determine whether or not a new version of an application uses an additional interface. The new clients must check for application compatibility by inquiring as to whether the new interface is supported. Compatibility is easily tested by calling the idl-generated bind( ) function with an object reference parameter, as described in the previous topic. An interface is not supported if the returned result is 0 (zero). This simple test implies that it is easy to create new versions of applications by adding additional interfaces, rather than running the risk of creating incompatibility by modifying existing interfaces.

The following example shows how to inquire if an interface is supported. Suppose we are told that some servers on our network implemented the overdraft account without using the Loan interface. This would not prevent our clients from creating and using overdraft objects; we would just not have the Loan interface to use to inquire about the status of an overdraft. In this scenario, the client that has the Savings interface could inquire as to whether the object also supports the Loan interface, as in the following:

iLoan = Loan::bind(ss);
if(iLoan == 0)
cout <<"Simple accounts do not support the Loan interface."<< endl;
iLoan = Loan::bind(od);
if(iLoan == 0)
cout <<
"This overdraft account doesn't support the Loan interface." << endl;

In the first case, attempting to bind a simple savings object to the Loan interface should always return 0 (zero). In the second case, if a zero value is returned, this overdraft object does not support the Loan interface (the Loan interface is not inherited).